Friday, February 1, 2013

get file size by jquery before upload

You actually don't have access to filesystem (for example reading and writing local files), however, due to HTML5 File Api specification, there are some file properties that you do have access to, and the file size is one of them.
For the HTML bellow
<input type="file" id="myFile" />
try the following:
//binds to onchange event of your input field
$('#myFile').bind('change', function() {

  //this.files[0].size gets the size of your file.
  alert(this.files[0].size);

});
As it is a part of the HTML5 specification, it will only work for modern browsers (and IE is not one of them).

No comments:

Post a Comment