Javascript :Is it possible to check image size in html fileupload on client side?
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>
精彩评论