Mini Shell
<?php
header('Content-Type: application/json');
include("../config.php");
$conn = dbconnect();
session_start();
$admin_id = $_SESSION['admin_id'];
// 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/brandimage/'; // Directory to save the uploaded video
// Validate file type (allow only video files)
$allowedTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/bmp', 'image/webp'];
if (!in_array($file['type'], $allowedTypes)) {
echo json_encode(['status' => '401', 'message' => 'Invalid file type.']);
exit;
}
// Remove spaces from the file name and add a timestamp
$originalFileName = $file['name'];
$fileExtension = pathinfo($originalFileName, PATHINFO_EXTENSION);
$fileName = uniqid() . '-' . time() . '.' . $fileExtension;
$filePath = $uploadDir . $fileName;
// Move the uploaded file to the desired directory
if (move_uploaded_file($file['tmp_name'], $filePath)) {
$sql = "INSERT INTO `brandimage` (`id`, `image`, `status`, `crm_id`, `created_log`, `updated_log`) VALUES (NULL, '$fileName', '1', '$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