Allow only pdf, doc, docx format for file upload?

前端 未结 8 2081
情深已故
情深已故 2020-12-24 13:18

I am triggering a file upload on href click.
I am trying to block all extension except doc, docx and pdf.
I am not getting the correct alert value.

&         


        
相关标签:
8条回答
  • 2020-12-24 14:10

    You can use

    <input name="Upload Saved Replay" type="file" 
      accept="application/pdf,application/msword,
      application/vnd.openxmlformats-officedocument.wordprocessingml.document"/>
    

    whearat

    • application/pdf means .pdf
    • application/msword means .doc
    • application/vnd.openxmlformats-officedocument.wordprocessingml.document means .docx

    instead.

    [EDIT] Be warned, .dot might match too.

    0 讨论(0)
  • 2020-12-24 14:11

    $('#surat_lampiran').bind('change', function() {
      alerr = "";
      sts = false;
      alert(this.files[0].type);
      if(this.files[0].type != "application/pdf" && this.files[0].type != "application/msword" && this.files[0].type != "application/vnd.openxmlformats-officedocument.wordprocessingml.document"){
      sts = true;
      alerr += "Jenis file bukan .pdf/.doc/.docx ";
    }
    });

    0 讨论(0)
提交回复
热议问题