使用 IE:
<html>
<head>
<script>
function getSize()
{
var myFSO = new ActiveXObject("Scripting.FileSystemObject");
var filepath = document.upload.file.value;
var thefile = myFSO.getFile(filepath);
var size = thefile.size;
alert(size + " bytes");
}
</script>
</head>
<body>
<form name="upload">
<input type="file" name="file">
<input type="button" value="Size?" onClick="getSize();">
</form>
</body>
</html>
使用 Chrome 或 Firefox:使用 jQuery 和 HTML5 File API 规范实现后,您可以使用这个简单的代码段来访问文件属性,例如大小:
//binds to onchange event of your input field
$('#myFile').bind('change', function() {
alert(this.files[0].size);
});
来源:关于该主题的优秀文章:http ://www.kavoir.com/2009/01/check-for-file-size-with-javascript-before-uploading.html