How can the PHP script be modified to use move_uploaded_file instead of copy for better file handling?

Using move_uploaded_file instead of copy is a better practice for file handling in PHP because it moves the uploaded file to a new location rather than creating a duplicate copy. This helps to prevent issues with file permissions, disk space, and potential security vulnerabilities. To modify the PHP script to use move_uploaded_file, simply replace the copy function with move_uploaded_file in the code.

<?php
$uploadDir = 'uploads/';
$uploadFile = $uploadDir . basename($_FILES['file']['name']);

if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Upload failed";
}
?>