I have an array of files and I want to be able to submit the form even if the file input fields are empty, but if they are not empty then check if its bigger than 5Mb. I could check if the file is bigger than 5Mb and if it is then it prevents form submit. but if the input file fields are empty the form will not allow me to submit. please help
if (window.File && window.FileReader && window.FileList && window.Blob){
//get the file size and file type from file input field
var fsize = $('.upload_files')[0].files[0].size;
if(fsize>5242880) //do something if file size more than 1 mb (1048576)
{
error_alert("file size is too big! please choose a smaller file");return false;
}
}