onlinecode

How to check file size when select multiple file validation using Jquery?

How to check file size when select multiple file validation using Jquery?

In this post we will give you information about How to check file size when select multiple file validation using Jquery?. Hear we will give you detail about How to check file size when select multiple file validation using Jquery?And how to use it also give you demo for it if it is necessary.

Sometimes we require to add validation of max file size using jquery, If we have only single file for validation then we can do it easily that, but if we have multiple file then you have to calculate size of all selected files and then check max required file size.

So, in this example you can see how to check validation for max size in multiple file select using jquery.

Example:

<html lang="en">

<head>

<title>Jquery - multiple image upload with size validation</title>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>

</head>

<body>


<div >


<div >

<input type="file" id="fUpload" multiple />

<button>Save</button>

</div>


<script type="text/javascript">

$(document).ready(function(){

$('#fUpload').change(function(){

var fp = $("#fUpload");

var lg = fp[0].files.length; // get length

var items = fp[0].files;

var fileSize = 0;

if (lg > 0) {

for (var i = 0; i < lg; i++) {

fileSize = fileSize+items[i].size; // get file size

}

if(fileSize > 2097152) {

alert('File size must not be more than 2 MB');

$('#fUpload').val('');

}

}

});

});

</script>


</div>


</body>

</html>

Hope this code and post will helped you for implement How to check file size when select multiple file validation using Jquery?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs

For More Info See :: laravel And github

Exit mobile version