Are there any best practices for efficiently handling file uploads in PHP?

When handling file uploads in PHP, it is important to validate the file type, size, and ensure secure storage. One best practice is to use move_uploaded_file() function to move the uploaded file to a designated directory on the server. Additionally, consider using a unique filename to prevent overwriting existing files.

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

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