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>

posted @ 2013-06-08 12:56  独行客  阅读(279)  评论(0编辑  收藏  举报