2

I am trying to validate file size, which I am trying to upload by a File Upload Control. To validate the size of the file, I am using java script code. But it is throwing run time error. Please somebody help me.

<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 / (1024 * 1024);
        alert(size + "MB");
    }
</script>

Error message : Microsoft JScript runtime error: Automation server can't create object

1

2 Answers 2

2

Javascript has no access to the filesystem so its not possible to check the size of the file by javascript.

and

new ActiveXObject("Scripting.FileSystemObject"); - is supported by IE only so do check you are suing IE not other browser.

Check this : How to validate upload file size and file extension using JavaScript ?

Sign up to request clarification or add additional context in comments.

1 Comment

True, you only can with html5.
0

File size can only be retrieved in browsers other than IE while using Javascript..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.