What are the best practices for handling file uploads in PHP to avoid issues with file size limitations?

When handling file uploads in PHP, it is important to consider the limitations set by the server configuration, such as maximum file size limits. To avoid issues with file size limitations, you can check the uploaded file size before processing it and provide appropriate error messages to the user if the file exceeds the limit.

<?php
// Check if the uploaded file exceeds the maximum file size limit
$maxFileSize = 10 * 1024 * 1024; // 10 MB
if ($_SERVER['CONTENT_LENGTH'] > $maxFileSize) {
    echo "Error: File size exceeds the limit of 10MB.";
    exit;
}

// Process the uploaded file if it does not exceed the limit
// Your file upload handling code here
?>