What are the advantages and disadvantages of using copy() versus move_uploaded_file() for handling file uploads in PHP?

When handling file uploads in PHP, using the copy() function is advantageous because it allows you to easily duplicate the uploaded file to a specified destination without affecting the original file. However, move_uploaded_file() is preferred when dealing with security concerns as it ensures that the uploaded file is moved to a specified location and also performs additional checks to verify the file's integrity.

// Using copy() function for file upload
$sourceFile = $_FILES['file']['tmp_name'];
$destinationFile = 'uploads/' . $_FILES['file']['name'];

if (copy($sourceFile, $destinationFile)) {
    echo 'File uploaded successfully.';
} else {
    echo 'Error uploading file.';
}

// Using move_uploaded_file() function for file upload
$sourceFile = $_FILES['file']['tmp_name'];
$destinationFile = 'uploads/' . $_FILES['file']['name'];

if (move_uploaded_file($sourceFile, $destinationFile)) {
    echo 'File uploaded successfully.';
} else {
    echo 'Error uploading file.';
}