Detecting File Upload size in jQuery
Using the HTML5 File API, we can detect the size of an uploaded file.
HTML
<form action="upload" enctype="multipart/form-data" method="post">
Upload image:<br />
<input id="image-file" type="file" name="file" /><br />
<input type="submit" value="Upload" />
</form>
SCSS
// TITLE: Detecting File Upload size in jQuery
// DESCRIPTION: Using the HTML5 File API, we can detect the size of an uploaded file.
// CREDIT: http://stackoverflow.com/questions/3717793/javascript-file-upload-size-validation
JavaScript
$('#image-file').bind('change', function() {
var file_size = this.files[0].size/1024/1024;
if(file_size == '0.1') {
alert('file is too small');
} else {
alert('working fine.');
}
});