js取得上传图片大小

<form enctype='multipart/form-data' action='doupload.php' name="form1" method='POST' onsubmit="return check_form()">
File:<input name='uploaded' id='uploaded' type='file'/><input type='submit' value='Upload'/>
</form>
<script>
function check_form(){
var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
var ele=document.getElementById("uploaded");
var fileSize = 0;
if (isIE && !ele.files) {
var filePath = ele.value;
var fileSystem = new ActiveXObject("Scripting.FileSystemObject");
var file = fileSystem.GetFile (filePath);
fileSize = file.Size;
}else {
fileSize = ele.files[0].size;
}
var size = fileSize / 1024; alert(size); return false;

if (errorMsg.length > 0){
alert(errorMsg); return false;
}else{
return true;
}
}
</script>

原文地址:https://www.cnblogs.com/yiwd/p/3126528.html