Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

behavior when post_max_size is exceeded



3:11 pm on Jan 28, 2005 (gmt 0)

10+ Year Member

Greetings fellow PHPers:

I am trying to set an 8MB limit on files that users can upload. In php.ini I have set upload_max_filesize to 8MB and post_max_size to 12MB. If a user uploads a 10MB file, then $_FILES['filename']['error'] equals 1, as expected. However if the user uploads a 13MB file, then PHP writes a warning message to syslog and simply gives up; it doesn't write *anything* to stdout! (I'm using PHP4.3 on WinXP with Apache2). I try to register my own error handler in the upload script but nothing happens; I'm guessing PHP gives up before the script ever gets loaded. And I have not been able to find documentation explaining how to gracefully trap the case where post_max_size is exceeded. (IMHO, setting post_max_size to 120MB is definately *not* graceful, because a 75MB file will still be uploaded, instead of interrupting the transfer after the limit has been exceeded.)

Can anyone point me to documentation, or offer any suggestions how I can get around this problem?

Thanks in advance,



4:41 pm on Jan 28, 2005 (gmt 0)

10+ Year Member

You could try putting your post limit in Apache's LimitRequestBody directive. The Apache docs say that an error is returned if the POST exceeds this limit, and you can probably trap this with ErrorDocument.


9:48 am on Jan 31, 2005 (gmt 0)

10+ Year Member

Ideally I should be able to do this in PHP itself. Unfortunately I don't find a description in the PHP doc for how PHP responds when post_max_size is exceeded; it only talks about how to increase the max size.


10:34 am on Jan 31, 2005 (gmt 0)

10+ Year Member

The "docs" are here [cvs.php.net]. Search for 'post_max'. It doesn't look like there's any way to trap this condition.


4:34 pm on Jan 31, 2005 (gmt 0)

10+ Year Member

you could always try preventing it with a hidden form element..

<input type="hidden" name="MAX_FILE_SIZE" value="10485760">

though some browsers may ignore this.



10:36 pm on Jan 31, 2005 (gmt 0)

10+ Year Member

...however the MAX_FILE_SIZE check in the form -- when not ignored by the browser -- will only take place after the entire file has been uploaded... which is exactly what I would like to avoid, in case some wiseguy tries to upload a 100MB file...

Featured Threads

Hot Threads This Week

Hot Threads This Month