本文介绍了限制文件上传选择到特定类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无论如何通过< input type =file/>
元素来限制文件类型的选择? $ b $例如,如果我只想要上传的图像类型,我会限制可能的选择(图像/ JPG,图像/ GIF,图像/ PNG),选择对话框会灰色的其他MIME类型的文件。
ps我知道我可以通过扫描.type属性在File API之后做到这一点。我真的想限制这一点,我也知道我可以做到这一点通过闪光灯,但我不想有这个使用闪光灯。
解决方案
这个特定的目的有一个html属性,叫做 accept
,但它在浏览器中几乎没有支持。
< input type =filename =picid = picaccept =image / gif,image / jpeg/>
如果您无法访问后端,请查看基于Flash的解决方案,如。
Anyway to restrict the selection of file types via the <input type="file" />
element?
<input type="file" name="pic" id="pic" accept="image/gif, image/jpeg" />
If you don't have access to the backend have a look at a flash based solution like SWFUpload.
See more on this here: File input 'accept' attribute - is it useful?
这篇关于限制文件上传选择到特定类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!