How can I save a file from a form to a specific folder in PHP?

To save a file from a form to a specific folder in PHP, you can use the move_uploaded_file() function. This function moves an uploaded file to a new location. You need to specify the temporary file path and the destination folder path where you want to save the file.

<?php
if(isset($_FILES['file'])){
    $file_name = $_FILES['file']['name'];
    $file_tmp = $_FILES['file']['tmp_name'];
    $destination_folder = 'uploads/'; // Specify the destination folder here
    move_uploaded_file($file_tmp, $destination_folder . $file_name);
    echo 'File uploaded successfully.';
}
?>