Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing only XML files in HTML file input element

How can I show only XML files in a file input element? I read about the "accept" attribute but also learned no browser actually support it. I found here some JS scripts but they didn't work well :-\

(I'm checking this server side as well but would like to do it client side too)

Thanks

like image 275
Shai Avatar asked Aug 13 '11 21:08

Shai


1 Answers

The answer is pretty simple, you use the MIME type. So if it is an xml file you want, you just do:

<input type="file" accept="text/xml" />

If you want to see the full list of MIME types, check this site http://www.iana.org/assignments/media-types/media-types.xhtml

like image 120
lordHougs Avatar answered Oct 09 '22 22:10

lordHougs