javascript - How to attach an event to check the file size before upload on all input type="file"? -


i attach event input type="file" on website check if file size superior 5mo, , if block upload , display warning instead. possible?

you can bind change event jquery:

$('input[type="file"]').change(function(){     var f=this.files[0];     var sizeinmb = f.size/1024;     var sizelimit= 1024*5; // if want 5 mb     if (sizeinmb > sizelimit) {         alert('sorry file exceeds maximum size of 5 mb!');         // reset input (code browser)         this.replacewith(input.val('').clone(true));         return false;     }     else {         // go on     } } 

hope helps.


Comments