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

Gulrej
  • 969
  • 4
  • 15
  • 25

2 Answers2

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 ?

Pranay Rana
  • 175,020
  • 35
  • 237
  • 263
0

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

Saiyam
  • 138
  • 2
  • 11