开发者

check file size using javascript before uploading

<html>
    <head>   
        <script>   
            function A()    
            {    
                var oas = n开发者_开发问答ew ActiveXObject("Scripting.FileSystemObject");    
                var d = document.a.b.value;    
                var e = oas.getFile(d);    
                var f = e.size;    
                alert(f + " bytes");    
            }    
        </script>    
    </head>    
    <body>    
        <form name="a">    
            <input type="file" name="b">    
            <input type="button" name="c" value="SIZE" onClick="A();">    
        </form>    
    </body>    
</html>   

this code is not working, i click the size button nothing is happen i checked ActiveXObject is not working i am using IE what is the reason for this


Instead of using ActiveXObject try this with jQuery

For the HTML bellow

<input type="file" id="myFile" />

try the following:

//binds to onchange event of your input field
$('#myFile').bind('change', function() {

  //this.files[0].size gets the size of your file.
  alert(this.files[0].size);

});

See following thread:

How to check file input size with jQuery?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜