6

I came across a browse file dialog-control tag in html and the tag was

<input id="myfile" name="myfile" type="file" accept="application/pdf"/>

but the 'accept' attribute doesn't seems to have any effect. I am using Internet Explorer 8.

wazz
  • 4,953
  • 5
  • 20
  • 34
subash
  • 4,050
  • 14
  • 51
  • 78

3 Answers3

13

according to the w3schools (http://www.w3schools.com/TAGS/att_input_accept.asp), the 'accept' attribute is not properly supported by any of the major browsers. The filter inside the file browser dialog will not work.

You could use a javascript validation on the form onsubmit event to verify if the file type is correct, returning false otherwise.

ghermeto
  • 154
  • 1
  • 2
  • 2
    I don't see in the page how it is not supported by the major browsers. – DrB Jul 13 '15 at 08:47
  • @BehnazChangizi The question and answer are both 5+ years old, and the answer is no longer correct. Most major browsers, including IE 10+, now support `accept`, and it's part of the HTML5 specification. – Mar Dec 01 '15 at 21:14
  • Still not supported properly in Dec 2015. For example, I'm trying to accept font files. I provide the following list of comma separated MIME content types to the "accept" attribute: "application/font-tdpfr,application/font-woff,application/x-font-bdf,application/x-font-ghostscript,application/x-font-linux-psf,application/x-font-otf,application/x-font-pcf,application/x-font-snf,application/x-font-ttf,application/x-font-type1". When the dialog box opens, the only items listed in the filetype dropdown are "All Files" and "WOFF File (.woff)". So it's completely broken. TTF, etc. are missing. – Triynko Dec 14 '15 at 14:56
  • Even just 2 years ago, the discussion was about a changing "standard" and how only one browser, Chrome, implemented support, and not even consistently. https://bugzilla.mozilla.org/show_bug.cgi?id=826176#c3 – Triynko Dec 14 '15 at 15:32
0

It seems like browsers have trouble following the IANA specifications found here: http://www.iana.org/assignments/media-types/media-types.xhtml

In my case, the application/pkcs* media types don't work at all, while for some reason application/x-pkcs12 works in chrome and partially(.p12) in IE. Firefox seems completely oblivious.

I also found this more optimistic discussion over here. File input 'accept' attribute - is it useful?

So, the best description would be "probably unsupported for uncommon formats", and with the x-pkcs vs pkcs confusion more or less unusable in my case.

Community
  • 1
  • 1
-1

Delimiter

HTML5 accept delimiter

I can confirm in some modern browsers that if you want the file dialog types to appear you need to use a comma as a delimiter:

<input accept="image/apng, image/jpeg, image/png" name="example" type="file" />
Community
  • 1
  • 1
John
  • 1
  • 13
  • 98
  • 177