Allow only pdf,doc,docx files for uploading with Jquery ?

Allow only pdf,doc,docx files for uploading with Jquery ?

Now if we want allow only pdf,doc, docx format files for file uploading, use the below code

Html

<input type="file" id="file" name="file[]" multiple="multiple" />

JQuery Script

if($('#file').val() != '') {            
      $.each($('#file').prop("files"), function(k,v){
          var filename = v['name'];    
          var ext = filename.split('.').pop().toLowerCase();
          if($.inArray(ext, ['pdf','doc','docx']) == -1) {
              alert('Please upload only pdf,doc,docx format files.');
              return false;
          }
      });        
}

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.


Share This Blog

Comment

Do you want to get our quality service for your business?