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.
Asked
Active
Viewed 5,034 times
5
-
The `$_FILES` array [will contain an error message](http://www.php.net/manual/en/features.file-upload.errors.php) if the maximum *file* size is exceeded. Not sure what happens if `post_max_size` breaks – Pekka Jun 07 '11 at 14:26
-
1@Pekka웃 - Both `$_FILES` and `$_POST` [become empty](http://es1.php.net/manual/en/ini.core.php#ini.post-max-size). – Álvaro González Jan 20 '14 at 10:44
2 Answers
2
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.

Gérald Croës
- 3,799
- 2
- 18
- 20
0
If you want to know if the file that was uploaded is too large you should use $_FILE['error'].

TJHeuvel
- 12,403
- 4
- 37
- 46
-
3the $_FILES (not $_FILE) array is blank as well, so this doesn't work. – McLeopold Jun 07 '11 at 14:23
-
1No you can't check if the file was to large (due to post_max_size) in $_FILES['error'] as super globals will be empty. It would have worked with upload_max_filesize though. – Gérald Croës Jun 07 '11 at 14:36