views:

30

answers:

3

Is it possible in PHP to detect when an upload failed because of filesize. I know about upload_max_filesize and post_max_size and set them to what i want but if a user doesn't see my file size limit (which is displayed in red) and uploads a large file it doesn't display an error. just takes a really long time.

I have <input type="hidden" name="MAX_FILE_SIZE" value="20000000" /> which i thought told the browser to check before sending but i guess not. (on firefox at least)

+5  A: 

http://www.php.net/manual/en/features.file-upload.errors.php

Wrikken
I don't get any file upload errors from PHP because post_max_size is triggered.
Samuel
You need to check $_FILES['userfile']['error'] to find the error. It's there.
John Conde
it's really not. I was already `print_r($_FILES)` but i just `echo $_FILES['upload']['error']` and nothing.
Samuel
A: 

The problem here is this: PHP doesn't even get a chance to start before the upload is complete; so the upload will "take a long" time anyway, only after that the upload_max_filesize is applied.

There is no way to check for filesize before the upload finishes - that is on the client side from JavaScript (and the browser won't do this for you); your best bet would be something like Uploadify - it's Flash based and I believe there's an option to check file size before starting the upload.

Piskvor
+1  A: 

You can check upload_max_fillesize by $_FILES['file’]['error'], but only if post_max_size is not triggered. In second situation, you can mark some way that there was a try to send a file, for example by adding parameter to action of your form like &filesended=1. And if you see that filesended is set, but $_POST global array is empty, that means user reached a post size limit.

killer_PL
I really didn't want to have to add something to the url but i guess that is the best solution. apart from using uploadify or something similar.
Samuel