VERY Ridicule PHP problem in file upload

i use this simple method for upload my file:

the hidden field

<input type="hidden" name="MAX_FILE_SIZE" value="30000" />

is before the file input use enctype=“multipart/form-data” for form …

but why when i upload larger file that MAX_FILE_SIZE php still wait for uploading file and do not stop uploading and give me
UPLOAD_ERR_FORM_SIZE and reject the file …


The MAX_FILE_SIZE is a hint for the browser. It could check the size of your file against this field, and warn you if the file is too large.

However, there are no browsers at all that do this, making the MAX_FILE_SIZE field somewhat redundant.

so i cannot reject request larger file that i need for my script …

i want to reject the larg file uploading request …
any method is here ???

You’re… slightly incorrect.

MAX_FILE_SIZE does get checked - at the PHP level, and AFTER the upload has completed. PHP has no way of knowing how big something is before you send all of it.

Think of it this way: I say to you, ‘I’m going to send you some apples.’. Am I going to send you 2? or 200,000,000? You dont know. How can you tell me if you have enough space if you dont know?

Now. It’s possible (though i havent explored the possibility, so i may be wrong) that Javascript might be able to head things off at the pass here. Form-validation, sort of.

You can reject larger files.

You need to code a php function for that.

the reqest from server send the post data that include file data and file content length !!! php cannot get that first and reject re reqeust ???

java script cannot get file size … just only with ActiveX that it’s just for IE on Windows OS … it’s not good way !!!

another way ?

GIV IT TO ME PLZ :smiley:

i can’t any function for reject the larger file on start upload … php wait for upload complete and then give me an error !!!

Well as far as I know, PHP will never give error before starting to upload. It will always check when the form will be submitted. (May be there are ways if any I dunno any but, more advance users can help it then.)

If you wanna check that before sending information to server, then you need some client side function or script.

While as for PHP goes, You need to define the file size to be accepted and then check that value with


Hope it will help.

PHP is serverside so can only check once the file has reached the server.
Javascript is clientside but can read the filesystem because of permissions.

You could use a JAVA applet or something like that. Maybe Flash could do it…

Playing devils advocate here…

Why reject a certain size file anyways?

I’ve found that this just REALLY frustrates users. Most of them don’t realize why their upload was rejected. MANY of them confuse image size (5" X 7") with File Size.

Long story short, I basically opened up the floodgates on my sites and allow virtually any size image to be uploaded. I then use an image processing script to size it down to the dimensions the site needs.

Now, that being said, I have full control over the people doing this uploading. So giving them full access such as this is not a compromise for anything other than server space (which is ultra cheap anyways).

Now, if you are doing this for a social network or something where any Joe Schmoe will be able to upload then yes, you may have to restrict. But otherwise, let them post whatever it is they want to post.

Just my $.02