<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);

// Set the maximum file size (2GB)
ini_set('upload_max_filesize', '2G');
ini_set('post_max_size', '2G');
ini_set('max_input_time', 300);
ini_set('max_execution_time', 300);

// Your hardcoded password
$correct_password = '3268';  // Replace with your actual upload password

if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['fileToUpload']) && isset($_POST['password'])) {
    // Check if the password is correct
    if ($_POST['password'] === $correct_password) {
        $target_dir = "a/";  // Ensure this directory exists and is writable
        $file_name = $_FILES['fileToUpload']['name'];
        $timestamp = date('Ymd'); // Condensed timestamp for the upload date
        $target_file = $target_dir . $timestamp . '_' . basename($file_name);

        // Check if file already exists
        if (file_exists($target_file)) {
            echo "Sorry, file already exists.";
        } else {
            // Try to upload the file
            if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_file)) {
                echo "The file " . htmlspecialchars($file_name) . " has been uploaded.";
            } else {
                echo "Sorry, there was an error uploading your file.";
            }
        }
    } else {
        echo "Invalid password provided.";
    }
} else {
    echo "No file uploaded or missing password.";
}
?>