What is the difference between using copy() and move_uploaded_file() functions in PHP for file handling?

The main difference between using copy() and move_uploaded_file() functions in PHP for file handling is that copy() creates a duplicate of the file in the destination folder, while move_uploaded_file() moves the uploaded file from the temporary directory to the specified destination. It is recommended to use move_uploaded_file() when handling uploaded files to ensure that the file is securely moved to the desired location without creating unnecessary duplicates.

// Example of using move_uploaded_file() function
$uploadedFile = $_FILES['file']['tmp_name'];
$destination = 'uploads/' . $_FILES['file']['name'];

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