Thursday, August 8, 2013

Get file size using Java Script only

HTML:
<input type="file" name="photo" id="photo" />

Java Script:
$('#photo').live('change', function(){
      var file_size=this.files[0].size;
      alert(file_size);
});

Notes:
1. This is a HTML5 feature. So I think its only works on HTML5 supported browsers.
2. Similarly we can get some attribute of file.

Source:
http://stackoverflow.com/questions/8192516/html5-file-browse-tag
http://forum.jquery.com/topic/how-to-validate-file-size-function-before-submitting-form

No comments:

Post a Comment

Learn JavaScript - String and its methods - 16

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>String and it's methods - JS&l...