JS 获取文件大小

jopen 6年前

<HTML>     <head>   <title>js获取文件大小</title>   <meta  http-equiv="content-type" content="text/html;charset=utf-8" >   <script type="text/javascript">                var isIE = /msie/i.test(navigator.userAgent) && !window.opera;  function fileChange(target) {     var fileSize = 0;     if (isIE && !target.files) {        var filePath = target.value;        var fileSystem = new ActiveXObject("Scripting.FileSystemObject");        var file = fileSystem.GetFile (filePath);        fileSize = file.Size;     } else {        fileSize = target.files[0].size;     }     var size = fileSize / 1024/1024;     alert('文件大小: '+size+'MB');  }          </script>  </head>   <body>      <input type="file" id="oFile" onchange="fileChange(this);" >      <input  type="button" value="获取文件大小"  onclick="testFileSize();">   </body>      <HTML>