
<?php
header('Content-Type: application/json');
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (isset($_FILES['video']) && $_FILES['video']['error'] === UPLOAD_ERR_OK) {
        $uploadDir = __DIR__ . '/uploads/videos';
        if (!is_dir($uploadDir)) mkdir($uploadDir, 0755, true);

        $tmpName = $_FILES['video']['tmp_name'];
        $name = basename($_FILES['video']['name']);
        $targetFile = $uploadDir . time() . '_' . $name;

        if (move_uploaded_file($tmpName, $targetFile)) {
            echo json_encode(['status' => 'success', 'file' => 'uploads/videos/' . basename($targetFile)]);
        } else {
            http_response_code(500);
            echo json_encode(['status' => 'error', 'message' => 'Could not move uploaded file.']);
        }
    } else {
        http_response_code(400);
        echo json_encode(['status' => 'error', 'message' => 'No file uploaded or upload error.']);
    }
} else {
    http_response_code(405);
    echo json_encode(['status' => 'error', 'message' => 'Invalid request method.']);
}
?>
