What are the limitations of using PHP to restrict file uploads based on size?
Limitations of using PHP to restrict file uploads based on size include the fact that PHP settings such as `upload_max_filesize` and `post_max_size` can limit the maximum file size that can be uploaded. Additionally, PHP may not be able to accurately determine the size of the file being uploaded if the upload is interrupted or if the file size exceeds PHP's internal limits.
// Check if the uploaded file size exceeds a specified limit (e.g. 5MB)
$maxFileSize = 5 * 1024 * 1024; // 5MB in bytes
if ($_SERVER['CONTENT_LENGTH'] > $maxFileSize) {
// File size exceeds limit, handle error accordingly
echo "Error: File size exceeds limit";
exit;
}