限制文件上传选择到特定类型 [英] restrict file upload selection to specific types
问题描述
< input type =file/>
元素来限制文件类型的选择? $ b $例如,如果我只想要上传的图像类型,我会限制可能的选择(图像/ JPG,图像/ GIF,图像/ PNG),选择对话框会灰色的其他MIME类型的文件。
ps我知道我可以通过扫描.type属性在File API之后做到这一点。我真的想限制这一点,我也知道我可以做到这一点通过闪光灯,但我不想有这个使用闪光灯。
这个特定的目的有一个html属性,叫做 accept
,但它在浏览器中几乎没有支持。
< input type =filename =picid = picaccept =image / gif,image / jpeg/>
如果您无法访问后端,请查看基于Flash的解决方案,如 SWFUpload 。
:文件输入接受属性 - 它有用吗? p> Anyway to restrict the selection of file types via the For instance, if I wanted only images types to be uploaded, I would restrict the possible selections to (image/jpg,image/gif,image/png), and the selection dialog would grey out files of other mime types. p.s. I know that I can do this after the fact with the File API by scanning the .type attributes. I'm really trying to restrict this before hand.. I also know I can do this via flash, but I do NOT want to have use flash for this. There is an html attribute for this specific purpose called 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? 这篇关于限制文件上传选择到特定类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!<input type="file" />
element?accept
but it has little support across browsers. Because of this server side validation is recommended instead.<input type="file" name="pic" id="pic" accept="image/gif, image/jpeg" />