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?
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.
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.
...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...