1

I have a form file upload. When the users goes to upload an image, it displays all files on their computer. How can I make the HTML upload dialog window to only display JPG, GIF and PNGs?

Teddy
  • 11
  • 1
  • 2
  • please consider the following post which may help you [Click][1] [1]: http://stackoverflow.com/questions/10381999/how-to-restrict-my-input-type-file-to-accept-only-png-image-files-not-working – laksys Sep 17 '12 at 04:29

3 Answers3

3

Just add accept to input with file types. This will filter the list of displayed files, but not create ban on download other files. This is convenient, because it is simple.

ilusionist
  • 31
  • 1
2

The file upload dialog in the web browser is outside of your control. You could create a Java applet for uploading images, like Facebook did.

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
  • Are you sure it's outside of my control? When I go to http://fotoflexer.com/ and click "Upload Photo", they seem to be limiting uploads based on filetype/extension. – Teddy Jun 16 '10 at 00:45
  • This answer is a bit old and should be updated to show ability to choose which files should be shown in the upload window – William Aug 26 '19 at 12:49
1

As this hasn't been answered yet; add the following code to your file input

accept="image/x-png,image/gif,image/jpeg"
Johannes
  • 377
  • 4
  • 17