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

When handling file uploads in PHP, it is important to consider any file size limitations that may be set on the server or in the PHP configuration. To address this issue, you can check the size of the uploaded file before processing it and provide appropriate error messages or take necessary actions if the file exceeds the size limit.

// Check if the uploaded file exceeds the maximum file size limit
if ($_SERVER['CONTENT_LENGTH'] > 1000000) {
    die('File size exceeds the limit of 1MB.');
}

// Process the uploaded file if it is within the size limit
else {
    // Process the file here
}