在html页面中,文件上传器只接受png

时间:2016-03-03 10:35:44

标签: jquery html css jpeg

我正在开发一款应用: 我有一个文件上传输入:

 <input id="full_demo" type="hidden" name="test[image]">

我想只允许.jpg格式, 有什么方法可以解决它。

在我的代码中文件类型=“隐藏”如果我将使用type =“file”那么cropper插件将停止工作。

我尝试过这段代码但没有工作:

<input type="file" name="pic1" accept="image/jpeg" /> 

3 个答案:

答案 0 :(得分:0)

它不是jpg的jpg。

<input type="file" name="pic1" accept="image/jpeg" /> 

答案 1 :(得分:0)

你可以尝试这样的事情。

<input type="file" name="pic1" id="image" accept="image/jpeg" />

您还可以提供多种格式。

<input type="file" name="pic1" id="image" accept="image/gif, image/jpeg, image/png" />

答案 2 :(得分:0)

<input type="file" name="myImage" accept="image/x-png, image/gif, image/jpeg" />

请注意,这只会向浏览器提供有关向用户显示哪些文件类型的提示,但这很容易被规避,因此您应始终在服务器上验证上传的文件。

它应该适用于IE 10 +,Chrome,Firefox,Safari 6 +,Opera 15+,但支持在手机上非常粗略(截至2015年),有些报道实际上可能会阻止某些移动浏览器上传任何内容所有,所以一定要很好地测试你的目标平台。

有关详细的浏览器支持,请参阅http://caniuse.com/#feat=input-file-accept