<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['csv_file'])) {
    if ($_FILES['csv_file']['error'] !== UPLOAD_ERR_OK) {
        exit("Error: Upload failed with error code " . $_FILES['csv_file']['error']);
    }

    $file = $_FILES['csv_file']['tmp_name'];

    // Include the CSV processing script
    require 'process_csv.php';

    // Call the function to process the file
    list($success, $fail) = processCSV($file);

    // Output result as plain text (not JSON)
    exit("Upload Complete. Success: $success, Failed: $fail");
}

exit("Error: Invalid request");
