如何在上传之前检索文件的大小? [英] How to retrieve the size of a file before uploading it?

查看:69
本文介绍了如何在上传之前检索文件的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网络应用中有一个文件输入标记。我想在将文件发送到服务器之前检查文件是否太大。当然,我还有验证服务器端。有没有办法用JavaScript做到这一点?它必须在IE7 +和FF3 +中工作。谢谢。

I have an file input tag in my web app. I'd like to check that the file isn't too big before sending it to the server. Of course, I still have validation server side. Is there any way to do this with JavaScript? It must work in IE7+ and FF3+. Thank you.

编辑:somefileinputobject.files [0] .filesize在FF中工作,但不在IE中工作。

somefileinputobject.files[0].filesize works in FF, but not IE.

推荐答案

这是一个难题。你必须使用AJAX,并使用浏览器发送到服务器上的文件大小标题。

It's a hard problem. You have to do it with AJAX, and use the filesize headers sent by the browser to the server on the POST request.

Yahoo的UI库有一个工具可以帮助解决这个问题。 。 YUI Uploader

Yahoo's UI Library has a tool to help with this. YUI Uploader

这篇关于如何在上传之前检索文件的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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