跨浏览器的客户端上传到服务器之前对文件大小的检查? [英] Cross-browser checking on file size at client side before uploading it to the server?

查看:109
本文介绍了跨浏览器的客户端上传到服务器之前对文件大小的检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

客户端验证重要的是要提高可用性。

Client side validation is important to improve usability.

有没有跨浏览器的方式,上传到服务器之前验证文件的大小。我使用asp.net文件上传控制。

Is there any cross-browser way to validate the file size before uploading it to the server. I am using asp.net file upload control.

我发现了一些第三方控件做检查:

I found some third-party controls do that check:

<一个href=\"http://ajaxuploader.com/Demo/simple-upload.aspx\">http://ajaxuploader.com/Demo/simple-upload.aspx

<一个href=\"http://demo.essentialobjects.com/Default.aspx?path=AJAXU\">http://demo.essentialobjects.com/Default.aspx?path=AJAXU

但如何?

推荐答案

previously,以确定之前发送文件到服务器的文件大小的唯一办法是让客户端插件比JavaScript的厚 /加载项。这些都必须在客户端系统上安装。例如。使用的SWFUpload,Java小程序,ActiveX控件。

Previously, the only way to determine the filesize before the file was sent over to the server was to have 'thicker than javascript' client-side plugins/add-ons. These would have to be installed on the client system. E.g. using SWFUpload, Java applets, ActiveX controls.

现在,你可以使用HTML5文件API,即:

Now, you can use the HTML5 File API, i.e.:

var size = document.getElementById('myfile').files[0].size;

这篇关于跨浏览器的客户端上传到服务器之前对文件大小的检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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