The below represents my script code
<script>
$(document).ready(function (){
$("#checkfields").click(function (){
var file1=$("#file1").val();
if(file1){
var file_size=$('#file1')[0].files[0].size;
if(file_size<2097152){
var ext = $('#file1').val().split('.').pop().toLowerCase();
if($.inArray(ext,['jpg','jpeg','gif'])===-1){
alert("Invalid file extension");
return false;
}
}else{
alert("Screenshot size is too large.");
return false;
}
}else{
alert("fill all fields..");
return false;
}
});
});
</script>
The below represents my code
<form action="checkmobile.php" method="post" enctype="multipart/form-data" class="form-horizontal">
<div class="form-group">
<label for="element-13" class="control-label col-lg-2">Add Screenshots</label>
<div class="input-group">
<input type="file" id="file1" name="file[]" class="btn" multiple="multiple">
</div>
</div>
<div class="form-group">
<input type="submit" id="checkfields" class="btn btn-primary col-lg-offset-2" value="Add">
<button class="btn btn-default col-lg-offset-1">Cancel</button>
</div>
</form>
Now I want to know how to use array in jQuery for validating all selected files under the input.
If I select one image and one video then it must check validation for image and video. first it will validate image if image is ok then it will reject the video by invalid extension.
i want to validation for all files while submitting the button and if image not valid then return error and if there is video selected with image then also it return error.
please help.