上传前检查文件大小
我有一个允许用户上传视频文件的网站,但我想将文件大小限制为 2MB,上传文件后这非常简单,但有人知道我是否可以在上传之前检查文件大小这样我就不会不必要地使服务器超载?
我可能正在寻找 javascript/ajax 解决方案,但我不知道如何实现这一点。
任何帮助将非常受欢迎。谢谢你们!
更新:
我需要检查客户端上的文件大小,而不是服务器端上的文件大小,这可能吗?
I have a website that allows users to upload video files but I want to limit the filesize to 2MB , this is pretty straightforward after uploading the file but does anyone knows if I can check the file-size before uploading it so I don't overload the server unnecessarily ?
I might be looking for a javascript/ajax solution but I don't have a clue on how to achieve this.
Any help will be very welcome. Thanks guys!
UPDATE:
I need to check the file size on client-side and NOT on server-side, is this possible ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 HTML5 中的
文件读取器
读取 JavaScript 中的本地文件:http://www.html5rocks.com/en/tutorials/file/dndfiles/
You can read local files in JavaScript using
file reader
in HTML5:http://www.html5rocks.com/en/tutorials/file/dndfiles/
如果您使用 php,您可以设置 php 选项 - 'upload_max_filesize'。请参阅 http://www.php.net/ Manual/en/ini.core.php#ini.upload-max-filesize 可能有帮助。
If you use php you can set php option - 'upload_max_filesize'. See http://www.php.net/manual/en/ini.core.php#ini.upload-max-filesize May be it helps.