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

When handling file uploads in PHP, it is important to validate the file type, size, and ensure proper file handling to prevent security vulnerabilities such as file injection attacks. It is recommended to use the move_uploaded_file() function to move the uploaded file to a secure location on the server.

if ($_FILES['file']['error'] === UPLOAD_ERR_OK) {
    $uploadDir = 'uploads/';
    $uploadFile = $uploadDir . basename($_FILES['file']['name']);

    if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) {
        echo "File is valid, and was successfully uploaded.";
    } else {
        echo "Upload failed.";
    }
} else {
    echo "Error uploading file.";
}