Internet Explorer 11获取文件大小
问题描述:
我试图从文件输入控件中获取文件的大小。 要做到这一点我使用jQuery:Internet Explorer 11获取文件大小
function init() {
$("#cphInhalt_cphInhalt_file0").bind("change", function() {
handleFileSelect(this);
});
}
function handleFileSelect(e) {
if (e.files[0].size + totalFileSize > 3000000) {
addNewUpload(e);
$(e).remove();
if (getCookie("language") == "German") {
alert("Die gesamte Dateigröße wurde überschritten");
} else {
alert("The total file size has been exceeded");
}
return;
}
在这工作得很好,除了IE(使用版本11)的任何浏览器,但我认为它应该支持一下文件API吗? 它说e.files是undefinied
答
它会要求在浏览器中启用ActiveX,请说让
<!DOCTYPE html>
<html>
<head>
<script language="javascript" type="text/javascript">
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>
这ANS在how validate file size using HTML and Javascript on client side
答
的问题是被赋予的是,IE设置他自己进入了版本7兼容模式。
您确定这适用于所有浏览器? http://www.html5rocks.com/en/tutorials/file/dndfiles/ – 2014-10-01 06:34:48
http://caniuse.com/#feat=fileapi它至少应该在IE chrome和firefox中工作,这对于这个项目来说非常重要 – Ced 2014-10-01 06:37:31
我的意思是,你确定这段代码有效吗? – 2014-10-01 06:38:08