how validate file size using HTML and Javascript on client side

后端 未结 3 992
轮回少年
轮回少年 2020-11-30 07:01

How can I validate the file size on the client side using JavaScript? I am using type=file for selecting the file

3条回答
  •  一生所求
    2020-11-30 07:27

    UPDATE 2013 as of this edit, the File API is supported in all major browsers, and in IE as of version 10

    http://caniuse.com/#search=file%20api

    You may still wish to use SWFUpload if you still need to support IE9 and under, though at this point it should probably be more of a fallback, since the html5 file api has support on mobile platforms where SWFUpload cannot reach. The html5 file api is based on firefox's file api as noted below.

    See also this duplicate question Client Checking file size using HTML5?

    UPDATE: Firefox has changed their API to this https://developer.mozilla.org/en/DOM/FileReader

    You can do it in firefox like so

    html:

    javascript:

    var filesize = document.forms[0].file.files[0].fileSize
    

    if there's a way to do this in IE, I don't know it. It probably involves activeX or some other such rubbish.

    edit: I found this here, HOW TO DO THIS IN IE

    
    
    
    
    

提交回复
热议问题