限制浏览窗口中显示的文件类型 [英] Limit File Types Shown in Browse Window

查看:182
本文介绍了限制浏览窗口中显示的文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否真的有所有限制在浏览文件窗口中显示的文件类型?我尝试过:

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只是忽略它。我发现了另一个问题的下面摘录:

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


Accept属性在
RFC 1867中引入,打算启用
基于MIME类型的文件类型过滤
用于文件选择控件。但是大多数,
如果不是全部,浏览器不使用
这个属性。

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.

我会检查所选择的项目文件类型在服务器端,但我想提高用户体验,通过使它更容易只显示XML文件。

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.

感谢所有的帮助。

推荐答案

AFAIK,没有办法这样做。下一个最好的事情是使用JS在提交表单之前检查文件扩展名,以便用户不会浪费时间上传不被接受的文件,而是服务器端文件类型检查例程应该保留,因为第一个方法很容易通过关闭JS关闭。

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.

这里是一个jQuery解决方案:如何在上传时限制文件类型?

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

希望这有助于。

这篇关于限制浏览窗口中显示的文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆