How do I prevent PHP from dying on larg uploads?

PHP dies if the file is too large. How can I prevent this so I can return an error?

ini_set does NOT work with upload_max_filesize since 4.2.3. You can try to modify it with HTACCESS, but once the file starts to execute, upload_max_filesize is locked.

You can try altering the values maximum values that php uses for uploads and script timeouts. See here.


ini_set('upload_max_filesize', '10m');

If you have access to php.ini, you can modify it there.

Otherwise, you cant.
EDIT: You CAN use the MAX_FILESIZE input name to nip it in the bud before it sends (Client Side prevention), but not PHP to prevent it.

OK, I figured it out. The image uploader has to be on a separate form because if it dies it kills the post. I set it up to open in a pop-up window. It uploads the file and then transfers the filename to the original form with a little javascript.

I’m still puzzled as to how to solve this. Adding the HTML hidden field only returns an error if the file is under the 8mb limit. Any other ideas?