如何在上传之前验证文件大小? [英] How to validate file size before uploading?

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

问题描述


可能重复:


GMail可以选择检查文件大小和提醒而不让页面回传。

我怎样才能自己实现这个功能?使用HTML5,你可以在客户端使用JavaScript实现这一点。这是jQuery,但它的工作原理当然没有: http://jsfiddle.net/pimvdb/S4mEv/ 2 / 。请注意,它并不适用于所有的浏览器(尚)。

  $('#file')。 
alert(this.files [0] .size +bytes);
});

https://developer.mozilla.org/en/DOM/File


Possible Duplicate:
How can you determine the file size in JavaScript?

GMail has the option to check file size and alerting without letting the page posting back.

How can I implement this feature myself?

解决方案

Using HTML5, you can achieve this on the client side using JavaScript. This is jQuery but it works without as well of course: http://jsfiddle.net/pimvdb/S4mEv/2/. Note that it's not available in all browsers (yet).

$('#file').change(function() {
    alert(this.files[0].size + " bytes");
});

https://developer.mozilla.org/en/DOM/File

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

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