7

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?

5
  • 2
    Can't you just do accept=".pdf, .xls"? 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 Commented Jun 4, 2018 at 18:04
  • 1
    Here is a format list: developer.mozilla.org/en-US/docs/Web/HTML/Element/input/… 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 Commented Jun 4, 2018 at 19:58
  • @FissureKing, "input type=file", the first link of search should help you. Commented Jun 4, 2018 at 20:07

2 Answers 2

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" 
Sign up to request clarification or add additional context in comments.

Comments

2

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 " /> 

1 Comment

It didn't work, but I did this: accept=".pdf, .xls, .xlsx" and it worked ;)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.