0
votes

I am using below code to restrict user to upload file formats i.e. in upload dialogue he will be able to see only those particular files.

type="file" accept=".pdf,.jpg,.jpeg,.jpe,.jfif,.tif,.tiff,.doc,.docx,.xls,.xlsx,.csv"

It works fine in Chrome, Mozilla and IE9 and above. But this is not working in IE8 and Safari.

How can I restrict in IE8 and Safari?

1
I was going through this link : wufoo.com/html5/types/14-file.html but seems I can't modify it for my requirement. - MaxWorld

1 Answers

0
votes

Typically it's better to check by mime type rather than file extension, as the name of the file can be changed to anything. This is also the standard for the accept property.

For your example in particular, you'd want to do something like this instead:

<input type="file" accept="application/pdf,application/msword,application/excel,image/jpeg,image/pjpeg,image/tiff,image/x-tiff" />

If you want more flexibility, you can also do stuff like accept="image/*,video/*" to accept all image and video types.

See this page for a list of mime types and their corresponding file extensions.