Search code examples
javascripthtmlformsfile-uploadfile-type

Limit document type for file upload box in web form?


Is there a way to set what file format types/filters through HTML or JavaScript?

I want the user to be able to select when he clicks the browse button on a web form. For example, I want to give him the option to select only JPG, GIF and PNG files for upload.

I know this is possible in Flash.


Solution

  • See input, accept (HTML element):

    accept
    If the value of the type attribute is file, this attribute indicates the types of files that the server accepts; otherwise it is ignored. The value must be a comma-separated list of unique content type specifiers:

        A valid MIME type with no extensions
        audio/* representing sound files HTML5
        video/* representing video files HTML5
        image/* representing image files HTML5
    

    Or see example here.