有没有任何jquery插件,将限制一个HTML文件上传只接受图像 [英] Is there any Jquery plugin that will restrict a HTML file uploader only to accept images
本文介绍了有没有任何jquery插件,将限制一个HTML文件上传只接受图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
意思是,我正在使用我自己的代码。但我没有找到一种方法来限制上传者接受的文件类型..我该怎么做? 。有什么插件只做这个功能(我不想使用一个完整的文件上传插件)
解决方案
HTML5,jQuery是不需要的。我认为它会足够小,以使用纯JavaScript:
- 首先,您可以设置接受属性至
image / *
- 之后,您可以使用文件Api < a>读取幻数的第一个字节 - 图片编号演示
这些只是一些想法。你可以设计一些启发式来检查文件类型。
I saw a lot of file up loader plugins .I dont want to use the entire file upload plugin ..
Means , I am using my own code. But i didnt find a way to restrict the file type the uploader accepts .. How can i do that? . Is there any plugin which doing only this function ( I don't want to use a full file uploader plugin)
解决方案
This requires HTML5, jQuery is not needed. I think it will be small enough to use pure JavaScript:
- first you can set the accept attribute to
image/*
- after that you can use the File Api to read the first bytes for the magic number - image numbers demo
These are just some ideas. You can devise some heuristic to check the file type based on this.
这篇关于有没有任何jquery插件,将限制一个HTML文件上传只接受图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文