本文转自http://blog.upall.cn/1215.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script>
var isIE = /msie/i.test(navigator.userAgent) && !window.opera;
function checkFileSize(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;
}
if (fileSize<70*1024*1024)
{
alert("图片大小超过70M,请处理之后重新上传!");
return false;
}
return true;
}
</script>
</head>
<body style="text-align:center">
上传头像:<input type="file" name="pic" id="pic" οnchange='checkFileSize(this);'/><br/>
<div id='box'>
头像预览:<img src="" id='aPic' style="display:none" width="100px" height="100px"/>
</div>
</body>
</html>