What alternative function could be used instead of copy() for file uploads in PHP, and why is it recommended?

Using the move_uploaded_file() function instead of copy() for file uploads in PHP is recommended because it is specifically designed for moving an uploaded file to a new location on the server. This function ensures that the file is uploaded securely and prevents any potential security risks that may arise from using copy().

// Example of using move_uploaded_file() for file upload
$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.";
}