HTML: How to limit file upload to be only images?(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:如何将文件上传限制为仅图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!