上传前检查文件大小的其他方法
有没有其他方法可以在上传之前检查文件的大小?要求是如果文件超出限制,则不得提交表单。如果不是,我必须使用表单进行普通上传,而不必使用 Flash 将文件准确上传到服务器。
Is there any other way that I can just check the size of a file before upload? The requirement is if the file exceeded the limit, the form mustn't submit. If it's not, I have to do the ordinary upload using the form and I don't have to exactly upload the file to the server using Flash.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
不在 JavaScript 中,文件大小不在 DOM 中。
Not in JavaScript, the file size is not in the DOM.
实例化 SWFUpload 时,需要传递两个参数:file_size_limit 和 file_queue_error_handler:
然后:
在开始上传之前检查文件大小是否在限制范围内
when instantiating SWFUpload, there are two parameters you need to pass: file_size_limit, and file_queue_error_handler:
and then:
this checks if the file size is within limits before starting the upload
使用 W3C FileAPI(至少由 Firefox 3.6 实现)即可。
有关详细信息,请参阅此链接
http://hacks. mozilla.org/2009/12/w3c-fileapi-in-firefox-3-6/
干杯
with the W3C FileAPI (implemented at least by Firefox 3.6) you can.
See this link for details
http://hacks.mozilla.org/2009/12/w3c-fileapi-in-firefox-3-6/
Cheers
可以通过 SWFUpload 控件检查文件大小。只需将 SWFUpload 控件放在 Web 表单标记之外即可。告诉用户单击 SWFUpload 按钮并指向他的上传文件。使用 javascript 确定文件大小,然后根据需要使用此信息,例如填充验证函数。然后您的主表单将需要要求用户再次指向他们的上传文件,并且正是这个字段将执行文件的实际上传。提交表单后,SWFUpload 控件将被完全忽略,因为它不是主表单的一部分。
Checking the file size through the SWFUpload control is possible. Just put the SWFUpload control outside of the Web form tags. Tell the user click on the SWFUpload button and point to his upload file. Use javascript to determine the file size, then utilize this information as you see fit such as populating a validation function. Then your main form will need to ask the user to point to their upload file again, and it is this field which will do the actual uploading of the file. When the form is submitted, the SWFUpload control will be completely ignored since it's not part of the main form.