< input type =" file">通过扩展限制可选文件 [英] <input type="file"> limit selectable files by extensions

查看:145
本文介绍了< input type =" file">通过扩展限制可选文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过扩展来限制可以使用input type =file元素选择的文件...?

how can someone limit the files that can be selected with the input type="file" element by extensions ... ?

我已经知道accept属性,但在chrome中它确实限制了最后一个定义的MIME类型(在本例中为gif)的文件,而FF4甚至没有限制任何内容。

I already know the accept attribute, but in chrome it does limit the files by the last MIME Type defined (in this case "gif") and FF4 does not even limit anything.

<input type="file" accept="image/jpg, image/gif">

我做错了什么?或者有其他的方式吗?

Am i doing anything wrong? Or is there an other way?

你的任何建议...

推荐答案

老实说,限制文件的最好方法是在服务器端。人们可以伪造客户端上的文件类型,以便在服务器传输时获取完整的文件名,解析出文件类型,然后返回消息通常是最好的选择。

Honestly, the best way to limit files is on the server side. People can spoof file type on the client so taking in the full file name at server transfer time, parsing out the file type, and then returning a message is usually the best bet.

这篇关于&lt; input type =&quot; file&quot;&gt;通过扩展限制可选文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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