Proper way to detect that post_max_size was exceded in php? [duplicate]
What is the proper way to detect that post_max_size was exceded in php? It looks like I can only check for an empty $_POST array, which seems imprecise. I need to detect if a file that was uploaded was to big and produce a proper error message.
You can't, if the value of post_max_size is exceeded, super globals will be empty.
A solution is to add in your form a $_GET variable
<form action="check.php?shouldHaveFilesInHere">
and to check if other super globals are filled or not in check.php.
http://www.php.net/manual/en/ini.core.php#ini.post-max-size
If you want to know if the file that was uploaded is too large you should use $_FILE['error'].
http://php.net/manual/en/features.file-upload.errors.php
精彩评论