Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recommended way to check file size on upload

I am working on a web application which supports file uploading. I am already familiar checking the size in server side, but i wanted to check the file size in a client side.

I know its a browser limitation that we cant access the file properties for security reasons. So i have tried both swfupload and uploadify component. Both are good and serve the needs.

But the limitation is both depends on flash, so if my end user not installed flash then i would end up in a problem. Asking them to install flash is another thing, but its a web portal and the user base is huge. So i don't like the idea of asking them to install flash.

Today i came across file upload functionality in gmail. And tested this in browser(IE) without having flash installed. What i found was interesting. If you upload a big file, they made a postback and immediately returning the message the file size is too large.

How this is possible, how they can find the size of the file without downloading the whole content.? I believe this must be done by reading HTTP header info. am i right?

So this is the exact functionality i wanted to implement. If the flash is installed already, i can use uploadify to check the size otherwise may be i ll implement-the-never-heardof-technique-used-by-google.

can someone recommend me how to do this?

anybody faced the similar problems earlier, what have you done??

Update:

Gmail upload with flash installed in FF

alt text

without flash in IE

alt text

like image 993
RameshVel Avatar asked Nov 17 '10 12:11

RameshVel


People also ask

How do I handle large uploads?

Possible solutions: 1) Configure maximum upload file size and memory limits for your server. 2) Upload large files in chunks. 3) Apply resumable file uploads. Chunking is the most commonly used method to avoid errors and increase speed.

How can I check the size of my server limit?

If you want to see if one of these has worked, simply go to “Jetpack CRM > System Assistant > System Status” and there you can see the value “Max File Upload Size”. Most hosting companies get asked this question all the time. Here's what you need to copy & paste to them.


2 Answers

You may take a look at the File API which is a draft for HTML 5. Here's a nice article. That's what Gmail uses if the browser supports it of course. But there's no way to ensure this will work across all browsers.

like image 77
Darin Dimitrov Avatar answered Oct 20 '22 18:10

Darin Dimitrov


In IE, you can do it with JS and ActiveX:

function A()
{
  var oas = new ActiveXObject("Scripting.FileSystemObject");
  var d = document.a.b.value;
  var e = oas.getFile(d);
  var f = e.size;
  alert(f + " bytes");
}

</script>
</head>
<body>
<form name="a">
<input type="file" name="b">
<input type="button" name="c" value="SIZE" onClick="A();">
</form>
</body>
</html>
like image 29
Service Informatique Avatar answered Oct 20 '22 19:10

Service Informatique