Deepak Deepak - 6 months ago 34
HTML Question

Restrict file upload type to only Image

I am using a HTML form to upload image files. Now i am using server side validation to allow the file types. But i want to validate it in client side as well. I have seen in some websites which greys out other file types when we are choosing the file. I think that is a cool option. When i was walking through google i found this

<input id="my_file_element" type="file" name="file_0" accept="image/*">

But with this i am getting "All Files" option so tat i can enable other files as well. I don't need that. No matter what happens the user should be allowed to select only images files from their computer. Do you guys know a way to do this ?

This is what i meant by greying out.
enter image description here


This accept attribute is a HTML5 feature and so is unsupported by a lot of browsers.

I'm afraid that, as long as I remember, the only other way to get a better file upload dialog (filetype filters, multiple files...) is to use a Flash object.