What is the significance of using move_uploaded_file() over copy() function in PHP for file upload operations?

The move_uploaded_file() function is specifically designed for handling file uploads in PHP and is recommended over the copy() function for security reasons. Using move_uploaded_file() helps prevent potential security risks by ensuring that the uploaded file comes from a form submission and was not tampered with during the upload process.

<?php
$target_directory = "uploads/";
$target_file = $target_directory . basename($_FILES["fileToUpload"]["name"]);

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
    echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
    echo "Sorry, there was an error uploading your file.";
}
?>