Mini Shell

Direktori : /home2/aravindar/public_html/admin/ajax/
Upload File :
Current File : /home2/aravindar/public_html/admin/ajax/achievementinsert.php

<?php
header('Content-Type: application/json');
include("../config.php");
$conn = dbconnect();
session_start();
$admin_id = $_SESSION['admin_id'];
$type = $_POST['type'];
$title = $_POST['title'];
$description = $_POST['description'];
// Check if the form was submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    // Check if a file was uploaded
    if (isset($_FILES['video']) && $_FILES['video']['error'] === UPLOAD_ERR_OK) {
        $file = $_FILES['video'];
        $uploadDir = '../dynamic_image/achievements/';

        $allowedTypes = ['image/jpeg', 'image/png'];
        if (!in_array($file['type'], $allowedTypes)) {
            echo json_encode(['status' => '401', 'message' => 'Invalid file type.']);
            exit;
        }

        $originalFileName = $file['name'];
        $fileExtension = pathinfo($originalFileName, PATHINFO_EXTENSION);
        $fileName = uniqid() . '-' . time() . '.' . $fileExtension;
        $filePath = $uploadDir . $fileName;

        if (move_uploaded_file($file['tmp_name'], $filePath)) {
            $sql = "INSERT INTO `tb1_achievements` (`id`, `title`, `description`, `image`, `status`, `crm_id`, `created_log`, `updated_log`) VALUES (NULL, '$title', '$description', '$fileName', '$admin_id', '', current_timestamp(), current_timestamp());";
            $content_res = mysqli_query($conn, $sql);
            echo json_encode(['status' => '200', 'message' => 'File uploaded successfully.', 'file_path' => $filePath]);
        } else {
            echo json_encode(['status' => '500', 'message' => 'Failed to move uploaded file.']);
        }
    } else {
        echo json_encode(['status' => '500', 'message' => 'No file uploaded or file upload error.']);
    }
} else {
    echo json_encode(['status' => '500', 'message' => 'Invalid request method.']);
}

Zerion Mini Shell 1.0