Jump to content

PHP warning when POST data exceeds post_max_size


earmsby

Recommended Posts

Hi,

 

I'm new to the forum (just registered today, in fact) but I did try searching for the information I'm looking for before posting.  Here's my question:

 

Where does the PHP Warning originate that warns when the size of POST data exceeds the value set in php.ini?  This error seems to be thrown before the page is loaded and therefore seems difficult (if not impossible) to trap or prevent from displaying.

 

As an example of what I mean, I tried completely preventing errors from displaying by using "error_reporting(0);"  That worked fine for other errors but when data was submitted on a form which exceeded the 8M set in the php.ini file, the error appears despite this function at the top of the page to which the form data is sent.

 

I notice that the error itself references "Unknown" as the file name so I suspect this error is being generated prior to the script even running at all.

PHP Warning: POST Content-Length of 10890420 bytes exceeds the limit of 8388608 bytes in Unknown on line 0

Essentially, what I am trying to do is detect if the POST data exceeds the php.ini limit and display a more user friendly error than the PHP Warning.  My users are likely to upload files approaching the limit so I need to be able to give them a message that the file they tried is too big.

 

I discovered that adding the hidden form field MAX_FILE_SIZE and setting the value lower than the post_max_size value does nothing since this would only be evaluated if the POST data could be read.  Instead the entire $_POST array seems to be discarded when it exceeds the post_max_size.

 

I have done multiple searches on this topic in this forum and in other PHP forums and mostly what I found is advice to increase the setting in php.ini but this is not an option for me.

 

Surely, others have run into this and found a solution.

 

And suggestions?

Link to comment
Share on other sites

To the best of my knowledge, modern php versions don't issue such a message, you just get an empty post and files array.

 

What php version? I suspect a php bug.

 

Edit: Apparently the output of the error message to stdout is server specific (though it is probably due to a startup errors setting in php.ini) - http://bugs.php.net/bug.php?id=31775

 

What is the display_errors setting shown in your phpinfo() output? I recommend setting display_errors to OFF on a live server, either in the master php.ini, a .htaccess file (when php is running as an Apache module), or in a local php.ini (when php is running as a CGI application.)

Link to comment
Share on other sites

Hi,

 

Thanks for answering my post.  On my development server I am running version 5.2.5 and the setting display_errors is set to OFF.

 

I am trying a similar script on my production server which is a shared hosting account on a remote server, however it times out before it can try to process the uploaded file (which is a whole other can of worms I'll need to solve!).

 

Thanks for any insight!

Link to comment
Share on other sites

Thanks for looking into this.  On my local server both display_errors and display_startup_errors are set to OFF.  I notice on the host's phpinfo() that they have display_errors set to ON and display_startup_errors set to OFF.  I don't know if it makes a difference because the upload times out before it gets to that point.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.