Get file size before uploading

Nisanth Kumar picture Nisanth Kumar · Sep 21, 2011 · Viewed 243.9k times · Source

Is there any way to find out the file size before uploading the file using AJAX / PHP in change event of input file?

Answer

Brij picture Brij · Sep 21, 2011

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);

});

See following thread:

How to check file input size with jQuery?