限制文件上传的大小(html输入) [英] Limit the size of an file upload (html input)
问题描述
我认为maxlength = 20000 = 20k,但这似乎不起作用。
我想只限制用户可以上传的文件的大小。 。
我在Rails上运行,而不是PHP,但认为它会很多更简单的做HTML / CSS中的客户端,或者作为使用jQuery的最后手段。这是非常基本的,但必须有一些HTML标记我缺少或不知道。
寻求支持IE7 +,Chrome,FF3.6 +。如果有必要,我想我可以轻易支持IE8 +。
谢谢。
你不能在客户端做它。你必须在服务器上完成它。
编辑:此答案已过时! ,HTML文件API 主要受所有主流浏览器支持。
我会为解决方案提供更新,但@ mark.inman.winning 已经完成了。
请记住,即使现在可以在客户端上进行验证,但您仍然应该在服务器上验证它。所有客户端验证都可以绕过。
I would like to simply limit the size of a file that a user can upload.
I thought maxlength = 20000 = 20k but that doesn't seem to work at all.
I am running on Rails, not PHP, but was thinking it'd be much simpler to do it client side in the HTML/CSS, or as a last resort using jQuery. This is so basic though that there must be some HTML tag I am missing or not aware of.
Looking to support IE7+, Chrome, FF3.6+. I suppose I could get away with just supporting IE8+ if necessary.
Thanks.
You can't do it client-side. You'll have to do it on the server.
Edit: This answer is outdated!
As the time of this edit, HTML file API is mostly supported on all major browsers.
I'd provide an update with solution, but @mark.inman.winning already did it.
Keep in mind that even if it's now possible to validate on the client, you should still validate it on the server, though. All client side validations can be bypassed.
这篇关于限制文件上传的大小(html输入)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!