Cross-browser client-side file size verification before uploading to server?

Client-side validation is important to improve usability.

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

I found that some third-party controls check:

http://ajaxuploader.com/Demo/simple-upload.aspx

and

http://demo.essentialobjects.com/Default.aspx?path=AJAXU

but how?

+5
source share
2 answers

, , , , javascript, /. . . SWFUpload, Java-, ActiveX.

API HTML5, ..:

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

API HTML5:

<script>
    var myFile = document.getElementById('myFile');
    var size;
    myFile.addEventListener('change', function() {
        size = this.files[0].size;
    });
</script>

.

Internet Explorer , ActiveX, Internet Explorer, .

, Flash, SWFUpload, IE9 , IE10 () API HTML5.

+4

All Articles