How to gracefully handle files that exceed PHP’s `post_max_size`?

From the documentation :

If the size of post data is greater
than post_max_size, the $_POST and
$_FILES superglobals are empty
. This
can be tracked in various ways, e.g.
by passing the $_GET variable to the
script processing the data, i.e. <form
action=”edit.php?processed=1″>, and
then checking if $_GET[‘processed’] is
set.

So unfortunately, it doesn’t look like PHP sends an error. And since it sends am empty $_POST array, that is why your script is going back to the blank form – it doesn’t think it is a POST. (Quite a poor design decision IMHO)

This commenter also has an interesting idea.

It seems that a more elegant way is
comparison between post_max_size and
$_SERVER[‘CONTENT_LENGTH’]. Please
note that the latter includes not only
size of uploaded file plus post data
but also multipart sequences.

Leave a Comment