<?php
// Check if the custom folder name is provided
if (isset($_POST['customFolder']) && !empty($_POST['customFolder'])) {
    $customFolder = $_POST['customFolder'];

    // Ensure the custom folder exists or create it
    if (!file_exists($customFolder)) {
        mkdir($customFolder, 0777, true);
    }

    // Check if a file was uploaded
    if (isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK) {
        $uploadedFile = $_FILES['file']['tmp_name'];
        $originalFileName = $_FILES['file']['name'];
        $destination = $customFolder . '/' . $originalFileName;

        // Move the uploaded file to the custom folder
        if (move_uploaded_file($uploadedFile, $destination)) {
            echo "File successfully uploaded to $destination";
        } else {
            echo "Error: Unable to move file to destination.";
        }
    } else {
        echo "Error: No file uploaded or an error occurred during upload.";
    }
} else {
    echo "Error: Custom folder name is missing or empty.";
}
?>
