首页 > 代码库 > js 获取文件大小

js 获取文件大小

<HTML><head> <title>js获取文件大小</title> <meta  http-equiv="content-type" content="text/html;charset=utf-8" > <script type="text/javascript">       var flag = true;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;      if (size>1.5){      alert("文件尺寸过大");      flag = false;   }      alert(flag);}     </script></head> <body>    <input type="file" id="oFile" onchange="fileChange(this);" >    <input  type="button" value="获取文件大小"  onclick="testFileSize();"> </body><HTML>

 

js 获取文件大小