I have some file requirement conditions which work fine with single file select but when using multiple file select it only counts the first file. I need it to determine the total sum of bites of all selected files and that all selected files have the accepted file extension. does anyone know how I can edit these conditions?
var file = document.getElementById('file');
var ext = file.value.substring(file.value.lastIndexOf('.') + 1);
if(ext!== "mp4" && ext!== "m4v" && ext!== "fv4"){
alert('not an accepted file extension');
return false;
} else
if (file.files[0].size >= 11000000) {
alert("File too Big");
return false;
}
<input name="uploaded[]" id="file" type="file" multiple />
You can map the
.filesto their sizes, and then add those sizes: http://jsfiddle.net/83F7B/.You can also loop over the
.fileswithforEachand check the extension of each file (or use.every).