Javascript:是否可以在客户端检查 html 文件上传中的图像大小?
最佳答案
JavaScript 无法做到这一点,它被禁止访问文件系统。 但是 VBScript 可以在 ActiveX 对象(Microsoft 专有脚本 API)的帮助下返回任何客户端文件的大小。
<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>
<input type="file" name="file">
<input type="button" value="Size?" onClick="getSize();">
关于JavaScript :Is it possible to check image size in html fileupload on client side?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4384815/