How to get file size for IE browser using javascript or jQuery?

I used the ActiveXObject browser for IE, but it does not work. I got the file size for other browsers in js but could not get the file size for IE browser. For this, I used the following code: -

if ($.browser.msie==true)
 {
     var fileSystemObject = new ActiveXObject("Scripting.FileSystemObject");
     var path = document.uploadDocumentForm.documentUpload.value;
     var file = fileSystemObject.getFile(path);
     var size = file.size;
     alert(size);

/*  var a = document.getElementById(fileId).value;
            $('#myImage').attr('src',a);
            var imgbytes = document.getElementById('myImage').fileSize;       
            alert("here"+imgbytes);
            var imgkbytes = Math.round(parseInt(imgbytes)/1024);        */

}
else
{
               var fileInput = $("#"+fileId)[0]; 
               var imgbytes = fileInput.files[0].size; 
              var imgkbytes = Math.round(parseInt(imgbytes)/(1024));
}   

Can anyone help me get the file size for IE browsers. I went through all the ideas, but could not get the file for IE browser. Please provide an idea or code for this ...

+3
source share
1 answer

It is assumed that the work follows.

<script type="text/javascript">
function AlertFilesize(){
    if(window.ActiveXObject){
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        var filepath = document.getElementById('fileInput').value;
        var thefile = fso.getFile(filepath);
        var sizeinbytes = thefile.size;
    }else{
        var sizeinbytes = document.getElementById('fileInput').files[0].size;
    }

    var fSExt = new Array('Bytes', 'KB', 'MB', 'GB');
    fSize = sizeinbytes; i=0;while(fSize>900){fSize/=1024;i++;}

    alert((Math.round(fSize*100)/100)+' '+fSExt[i]);
}
</script>

<input id="fileInput" type="file" onchange="AlertFilesize();" />

This was taken from another answer Get the file size before downloading .

0
source

All Articles