Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Limit File Types Shown in Browse Window

Is there really NO WAY AT ALL to limit the file types that are shown in a browse file window? I tried this:

<input type="file" accept="text/xml" name="parameter_file" />

Firefox, IE just ignore it. I found the below excerpt from another question:

Accept attribute was introduced in the RFC 1867, intending to enable file-type filtering based on MIME type for the file-select control. But most, if not all, browsers make no use of the this attribute.

How else can I do this? I know you can achieve this with Flash but I don't really want to use Flash.

I will be checking selected file type on the server side but I would like to improve user experience by making it easier to only show XML files.

Thanks all for any help.

like image 801
Abs Avatar asked Dec 16 '25 22:12

Abs


1 Answers

AFAIK, there is no way to do this. The next best thing would be to use JS to check the file extension before the form is submitted so the user won't waste time uploading a file that is not accepted, but the server-side file type check routine should also be kept, because the first method would be easily bypassed by turning JS off.

Here's a jQuery solution: How to have jQuery restrict file types on upload?

Hope this helps.

like image 56
Valentin Flachsel Avatar answered Dec 19 '25 10:12

Valentin Flachsel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!