<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $name = $_POST['name'];
    $path = $_POST['path'];
    $param1 = $_POST['param1'];
    $id = $_POST['id'];

    if (!file_exists($path)) {
        mkdir($path, 0777, true); // The third parameter ensures recursive directory creation
    }

    $uploadDirectory = $path.'/';

    // Get the original file extension
    $originalFileName = $_FILES['file']['name'];
    $extension = pathinfo($originalFileName, PATHINFO_EXTENSION);

    // Use $name as part of the filename and add the original file extension
    $uploadedFile = $uploadDirectory . $name . '.' . $extension;

    if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadedFile)) {
        echo 'File uploaded successfully.';
        
    } else {
        echo 'Error uploading file.';
    }
}
?>
