What is the difference between using copy and move_uploaded_file for file uploads in PHP?
When uploading files in PHP, it is important to understand the difference between using `copy` and `move_uploaded_file`. `copy` simply duplicates the file to the specified location, while `move_uploaded_file` moves the uploaded file to the specified location, typically used for handling file uploads. It is recommended to use `move_uploaded_file` when dealing with file uploads as it performs additional security checks to ensure the file was uploaded via HTTP POST.
// Using move_uploaded_file to handle file uploads
$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.";
}