jquery获取文件大小

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 <title>Get File Sizetitle> 
 <script src="http://code.jquery.com/jquery-1.11.0.min.js" type="text/javascript" > script>
 <script type="text/javascript">
 function GetFileSize(fileid) {
      
 try {
 var fileSize = 0;
 //for IE
 if ($.support.msie) {
 //before making an object of ActiveXObject, 
 //please make sure ActiveX is enabled in your IE browser
 var objFSO = new ActiveXObject("Scripting.FileSystemObject"); var filePath = $("#" + fileid)[0].value;
 var objFile = objFSO.getFile(filePath);
 var fileSize = objFile.size; //size in kb
 fileSize = fileSize / 1048576; //size in mb 
 }
 //for FF, Safari, Opeara and Others
 else {
 fileSize = $("#" + fileid)[0].files[0].size //size in kb
 fileSize = fileSize / 1048576; //size in mb 
 }
 alert("Uploaded File Size is" + fileSize + "MB");
 }
 catch (e) {
 alert("Error is :" + e);
 }
}
 script>
head>
<body>
<form name="upload" action="">
<input type="file" name="fUpload" id="fUpload" />
<input type="button" value="Get File Size" onclick="GetFileSize('fUpload');" />
form>
body>
html> 

转自CSDN
http://bbs.csdn.net/topics/390722613
2楼版主Return_false

你可能感兴趣的:(前端,jquery)