 <?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
    $file = $_FILES['file'];
    $filePath = __DIR__ . "/" . basename($file['name']); // Uploads to the same directory

    if (move_uploaded_file($file['tmp_name'], $filePath)) {
        $message = "File uploaded successfully: <a href='" . htmlspecialchars(basename($file['name'])) . "' target='_blank'>" . htmlspecialchars(basename($file['name'])) . "</a>";
    } else {
        $message = "L Failed to upload file.";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Simple File Uploader</title>
    <style>
        body { font-family: Arial, sans-serif; text-align: center; margin-top: 50px; }
        input, button { padding: 10px; margin: 10px; }
        ul { list-style-type: none; padding: 0; }
        li { margin: 5px 0; }
    </style>
</head>
<body>
    <h2>Upload Any File</h2>
    <?php if (isset($message)) echo "<p>$message</p>"; ?>

    <form action="" method="post" enctype="multipart/form-data">
        <input type="file" name="file" required>
        <button type="submit">Upload</button>
    </form>

    <h3>Uploaded Files:</h3>
    <ul>
        <?php
        $files = array_diff(scandir(__DIR__), array('.', '..', basename(__FILE__))); // Exclude this script
        if (empty($files)) {
            echo "<li>No files uploaded yet.</li>";
        } else {
            foreach ($files as $file) {
                if (is_file($file)) {
                    echo "<li><a href='$file' target='_blank'>$file</a></li>";
                }
            }
        }
        ?>
    </ul>
</body>
</html>