Does the file is being downloaded to site even if it's not supposed to be downloaded?
I am sure this is the one of the most epic titles ever. So, I have upload form like here. I made that people could upload their files only up to 1 MB. But, if I try to upload for example 1 GB file, it takes ages before it gives me an error. So, here comes a question. Before checking file's size, doe开发者_C百科s that file is being downloaded in my hosting or does it takes resources from my hosting? Why it takes ages and ages before it gives me an error although if I try to upload 2 MB file it gives me an error in 1 second? Thank you for your explanations.
If you're checking the file size on the server then, yes, it will have to upload to the server in order to just run the if statement that checks the size.
Anything you do on the client side to check will, of course, be at the mercy of the client. So there is no 100% reliable way to do it. Artefacto pointed out one good way to catch most users. There's also a JavaScript ActiveX object that might help (http://www.kavoir.com/2009/01/check-for-file-size-with-javascript-before-uploading.html) but, again, users can easily disable it (even quite unintentionally) or have browsers that don't support it at all.
You should include an input like:
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
that hints the browser in respect to the maximum file size that can be uploaded. Most browsers will then warn the user if the file is too bug.
I don't think PHP will store files past the maximum post size allowed in php.ini if the user submits one (the server will not have a 1GB file occupying space unnecessarily); however, the user must send all the data before it gets the error response for the server because the HTTP protocol has no provision for interrupting the client's request and send a response prematurely.
Beware that if allow huge POST data and defer the file size check to your PHP script, more disk space will be used.
Just having a quick google for your issue I found this old stackoverflow topic, Using jQuery, Restricting File Size Before Uploading It seems that it is infact possible to stop people uploading files to big client side but only using flash/Java, maybe this software will help http://www.swfupload.org/. 9th bullet point down on description: Control filesize before upload starts.
Regards
Luke
精彩评论