views:

153

answers:

4

Hello SO,

To increase user experience, I would like to warn the user that the file is too big (let's say > 8M) before sending the whole file (which may take some time due to the size and the client connection). All kind of fields can be "pre-validated" client-side for a better user experience, but I'm stuck on the file size problem.

Is there a solution to this problem?

[edit] I'm also open to APC for PHP, which features the rfc 1867. I'm not sure if it's possible to cancel the form upload if we detect the size is too big. I certainly will award bounty if someone show me how to do it.

+2  A: 

Here is a simple solution to that

http://www.kavoir.com/2009/01/check-for-file-size-with-javascript-before-uploading.html

change it to match your needs

but beware it has been reported that it doesn't work in some browsers, it might need some changes.

Flakron Bytyqi
Will only work in IE7 and below.
Alex Reitbort
Yes, that only works in IE. What about Firefox, Opera, Chrome and Safari ?
Savageman
+4  A: 

You can use the File API in new browsers that aren't IE. I found this tutorial with some Googling: http://www.html5rocks.com/tutorials/file/dndfiles/

Also, the MDC reference is here: https://developer.mozilla.org/en/DOM/File

Unfortunately I don't think there is a way in all versions of IE. Flakron's answer covers 6 and 7 it sounds like, but I'm not sure about 8 and I'm not familiar with the IE API. You probably would need to go with a plugin based uploder (Flash, Silverlight, or Java).

CalebD
Plugins have "strong" dependencies. I would like to avoid it if possible. That said, Flash uploader would not be a bad solution (with a fallback for a "classic" file input, of course).
Savageman
A: 

Is there a solution to this problem?

I think you'll end up regretting choosing a "too big" size to warn about, because transfer speed is the real determination of throughput.

It's better to simply show the estimated time to completion along with a cancel option. A progress thermometer is nice too. That way, the user can decide if it will take too long, regardless of file size or connection speed, and you'll never have to go back and modify your chosen "too big" limit when past big uploads turn into future minor tasks due to the inevitable performance increases.

joe snyder
How would you know the estimated time to completion in HTML with a HTTP upload though? The server doesn't know how big the file is until the browser has finished upload the entire file does it?
Matthew Lock
Unless he has a real "too big" on the backend.
Joshua
Yes, HTML controlling an HTTP upload is not a pleasant GUI. Try http://www.google.com/search?q=upload+progress
joe snyder
The whole thing is to not perform the transfert if the file is too big and warn the user before so he doesn't lose time.
Savageman
"Too big" is subjective. What's too big for user A might be tiny for user B, so don't bug user B with inapplicable warnings.
joe snyder
+6  A: 

How about this Flash based uploader? http://swfupload.org/

This seems compelling

  • Degrades gracefully to normal HTML upload form if Flash or javascript is unavailable
  • Control filesize before upload starts

Since it's open source if you were keen you could combine the graceful degradation with the other HTML5 and IE only solutions to cover most browser installs: http://code.google.com/p/swfupload/

Matthew Lock
+1 for SWFUpload. Despite the flash nature (even if just about everybody have Flash support...), this is the only rich full featured component I have found a few years ago (that an a signed Java applet...) that works great and does not impose a predefined user interface. You should also add that SWFUpload have upload progress monitoring, can select multiple files at once, and has an upload queue with possible size limit, etc.
Yanick Rochon
+1 and it work in all major browsers and have a wide range of callback handlers!
aSeptik

related questions