How does the choice between copy() and move_upload_file() impact file management efficiency in PHP?
When deciding between copy() and move_upload_file() in PHP, the choice impacts file management efficiency as copy() duplicates the file, while move_upload_file() moves the file from the temporary directory to the specified destination. If you want to simply move the file to a new location without creating a duplicate, move_upload_file() is the more efficient choice.
// Using move_upload_file() to efficiently move a file
$uploadedFile = $_FILES['file']['tmp_name'];
$destination = 'uploads/' . $_FILES['file']['name'];
if (move_uploaded_file($uploadedFile, $destination)) {
echo 'File moved successfully.';
} else {
echo 'Error moving file.';
}