开发者

Javascript :Is it possible to check image size in html fileupload on client side?

开发者 https://www.devze.com 2023-01-29 15:40 出处:网络
Javascript :开发者_如何学编程Is it possible to check image size in html fileupload on client side ?JavaScript is not able to do it, it\'s forbidden to access file system.

Javascript :开发者_如何学编程Is it possible to check image size in html fileupload on client side ?


JavaScript is not able to do it, it's forbidden to access file system. But VBScript, can return the size of any client file with the help of ActiveX Object, the Microsoft proprietary scripting 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();">


    <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>
0

精彩评论

暂无评论...
验证码 换一张
取 消