What are best practices for ensuring successful file uploads on a web server using PHP?

When uploading files to a web server using PHP, it is important to set appropriate file size limits, validate file types, and handle errors gracefully. To ensure successful file uploads, you can use PHP's built-in functions like `move_uploaded_file()` to move the uploaded file to a designated directory and check for any errors during the upload process.

<?php
// Check if the file was uploaded without errors
if ($_FILES['file']['error'] == UPLOAD_ERR_OK) {
    // Specify the directory where the file will be stored
    $uploadDir = 'uploads/';
    
    // Move the uploaded file to the specified directory
    if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadDir . $_FILES['file']['name'])) {
        echo 'File uploaded successfully!';
    } else {
        echo 'Error uploading file.';
    }
} else {
    echo 'Error: ' . $_FILES['file']['error'];
}
?>