HTML:如何将文件上传限制为仅图像? [英] HTML: How to limit file upload to be only images?

查看:39
本文介绍了HTML:如何将文件上传限制为仅图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 HTML,如何限制可以上传的文件类型?

With HTML, how do I limit what kind of filetypes can be uploaded?

为了方便用户体验,我想将文件上传限制为仅图像(jpeg、gif、png).

To easy the user experience, I want to limit file uploads to be only images (jpeg, gif, png).

<form method="post" action="..." enctype="multipart/form-data">
<label for="image">Photo</label>
<input name="image" type="file" />
</form>

推荐答案

HTML5 说 <input type="file" accept="image/*">.当然,永远不要相信客户端验证:总是在服务器端再次检查......

HTML5 says <input type="file" accept="image/*">. Of course, never trust client-side validation: Always check again on the server-side...

这篇关于HTML:如何将文件上传限制为仅图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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