0

I have a <input type="file" accept=".png,.jpg" /> element. with attribute accept.

But it is accepting all the files in the firefox and safari. It is working good in chrome and ie. How can i write code for all the browsers

Jonathan
  • 1,659
  • 8
  • 34
  • 54

2 Answers2

1

Try this:

<label>Select file: 
<input type="file" name="imagefile" accept="image/jpeg, image/png">
</label>

More info here: http://www.w3.org/wiki/HTML/Elements/input/file

opalenzuela
  • 3,139
  • 21
  • 41
  • BTW, Mozilla guys insists in that this IS supported: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input#attr-accept and it DOES work in FF 23.0.1 – opalenzuela Sep 05 '13 at 10:27
  • Your answer is correct (which is nice since most of the other answers in this thread are terrible). However, Firefox only appears to support wildcard MIME types in the `accept` attribute on file input elements, regardless of what MDN claims. At least on OS X. I haven't tested on Windows. – Ray Nicholus Sep 05 '13 at 14:28
  • Mmm.. I tried Firefox on Windows, and it does accept multiple MIME types. However, it displays as the first option "All files (*.*)", -which I don't understand- and in the subsequent options png/jpeg, png and jpeg (in this order). I believe is a WRONG implementation decision of the Mozilla guys, but still... it's the best I can get ;) – opalenzuela Sep 06 '13 at 10:52
  • So... is it a valid answer or not? ;) – opalenzuela Sep 10 '13 at 14:58
0

you can use this for all browser

<input type="file" name="pic" accept="image/*">
Ankur Dhanuka
  • 1,217
  • 2
  • 11
  • 22