What are common pitfalls to avoid when setting maximum file size limits for uploads in PHP?

Common pitfalls to avoid when setting maximum file size limits for uploads in PHP include not updating the php.ini file, not properly handling errors, and not checking the file size before processing the upload. To solve these issues, ensure that the php.ini file is updated with the desired maximum file size limit, handle file upload errors gracefully, and check the file size before processing the upload to prevent exceeding the limit.

// Set maximum file size limit in php.ini file
// upload_max_filesize = 10M

// Check file size before processing upload
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_FILES['file'])) {
    $fileSize = $_FILES['file']['size'];
    
    if ($fileSize > 10485760) { // 10MB in bytes
        echo "File size exceeds the limit of 10MB.";
    } else {
        // Process file upload
    }
}