<input name="" id="yourinputfieldis" onchange="checkFile()" type="file" multiple = "multiple" accept = "*">
<script>
function checkFile() {
var x = document.getElementById("yourinputfieldis");
var txt = "";
document.getElementById("demo").innerHTML = txt;
if ('files' in x) {
if (x.files.length == 0) {
txt = "Select one or more files.";
} else {
for (var i = 0; i < x.files.length; i++) {
var file = x.files[i];
if ('name' in file) {
var ext = file.name.split('.').pop().toLowerCase();
if($.inArray(ext, ['gif','png','jpg','jpeg','doc','pdf','xlsx']) == -1) {
txt += "name: " + file.name + "<br>";
document.getElementById("yourinputfieldis").value = "";
if ('size' in file) {
txt += "size: " + file.size + " bytes <br>";
}
alert('You are trying to upload files which not allowed ' + "(" + file.name + " is invalid)");
}
}
}
}
}
else {
if (x.value == "") {
txt += "Select one or more files.";
} else {
txt += "The files property is not supported by your browser!";
txt += "<br>The path of the selected file: " + x.value;
}
}
}
</script>