最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Input type='file' accept pdf and excel file extension - Stack Overflow

programmeradmin0浏览0评论

I want an input type="file" to accept only pdf and excel

I did this <input type="file" name="upload" accept="application/pdf,application/vnd.ms-excel" />

And it accepts .pdf and .xls files, but not .xlsx, how can I make it accept xlsx files as well?

I want an input type="file" to accept only pdf and excel

I did this <input type="file" name="upload" accept="application/pdf,application/vnd.ms-excel" />

And it accepts .pdf and .xls files, but not .xlsx, how can I make it accept xlsx files as well?

Share Improve this question edited Jun 4, 2018 at 18:07 Latika Agarwal 9691 gold badge6 silver badges11 bronze badges asked Jun 4, 2018 at 18:01 Lizz ParodyLizz Parody 1,76513 gold badges31 silver badges50 bronze badges 5
  • 2 Can't you just do accept=".pdf, .xls"? – Alon Eitan Commented Jun 4, 2018 at 18:04
  • 1 Have you tried other MIME types for xlsx? A quick google search suggested application/vnd.openxmlformats-officedocument.spreadsheetml.sheet – Fissure King Commented Jun 4, 2018 at 18:04
  • 1 Here is a format list: developer.mozilla.org/en-US/docs/Web/HTML/Element/input/… – Get Off My Lawn Commented Jun 4, 2018 at 18:06
  • @LizParody, Didn't want to be rude, it was just straight forward. Sorry, if you felt other way. Just for the next time sake, you can try searching for "file input html" or something like it, the MDN or w3c links should give you good examples for basic functionalities. Again, don't take it otherwise. Give it a good try yourself, before asking help, would help you in long run – Rahul R. Commented Jun 4, 2018 at 19:58
  • @FissureKing, "input type=file", the first link of search should help you. – Rahul R. Commented Jun 4, 2018 at 20:07
Add a comment  | 

2 Answers 2

Reset to default 14

Try following:

<input type="file" accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" />

In modern browser you can also use file extensions directly like:

accept=".pdf, .xls, .xlsx"

Try using this and let me know !

   <input type="file" accept=".pdf,.xls" />

EDIT Simply

<input type="file" accept="add all the extension of your choice separating by a comma " />
发布评论

评论列表(0)

  1. 暂无评论