开发者

check file size using javascript before uploading

开发者 https://www.devze.com 2023-02-20 19:32 出处:网络
<html> <head> <script> function A() { var oas = n开发者_开发问答ew ActiveXObject(\"Scripting.FileSystemObject\");
<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

精彩评论

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