<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Allow-Headers: Content-Type');

$uploadDir = 'uploads/';

if (!is_dir($uploadDir)) {
    mkdir($uploadDir, 0755, true);
}

if (isset($_FILES['excelFile'])) {
    $fileTmpPath = $_FILES['excelFile']['tmp_name'];
    $fileName = basename($_FILES['excelFile']['name']);
    $destination = $uploadDir . $fileName;

    if (move_uploaded_file($fileTmpPath, $destination)) {
        echo json_encode(['message' => 'File uploaded successfully']);
    } else {
        http_response_code(500);
        echo json_encode(['message' => 'Failed to move uploaded file']);
    }
} else {
    http_response_code(400);
    echo json_encode(['message' => 'No file uploaded']);
}
?>
