9

I used the following methode

HTML

<input type="file" id="loadfile" />

JavaScript

var file = document.getElementById('loadfile').files[0];
alert( "name " +  file.name + "Size " +  file.size );

It works fine other browsers except IE :( How to get in IE ?

Ash Burlaczenko
  • 24,778
  • 15
  • 68
  • 99
raki
  • 2,253
  • 8
  • 33
  • 42
  • 4
    IE doesn't support File API. – Ram Nov 22 '12 at 11:41
  • 2
    http://caniuse.com/#feat=fileapi – adeneo Nov 22 '12 at 11:42
  • Thanks all ... I also get the info from everywhere that IE doesn't support this feature :( I had found a great plugin for file upload http://blueimp.github.com/jQuery-File-Upload/ – raki Nov 22 '12 at 11:54
  • You may be able to do it if you use Flash. Is Flash not an option? We use a Flash uploader that does get filesize, but I think what we have is a custom built one, not some publicly available Flash uploader. But the publicly available ones might have that functionality as well. We use the Flash uploader in IE only and go with HTML5/JS based uploader on the other browsers. Suggest you look into the same approach. – David Mar 29 '13 at 06:43
  • This works from IE 10 onwards, also check whether you have meta element. e.g. . Use instead – RasikaSam Mar 20 '17 at 06:31

5 Answers5

5

IE doesn't supply file size information I'm afraid. You might be able to use HTML5 File API with IE10, see here:-

Javascript to check filesize before upload in Internet Explorer

Community
  • 1
  • 1
Lloyd
  • 29,197
  • 4
  • 84
  • 98
1

you can do it like this using activeX

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");
}

see here for more detail;

how validate file size using HTML and Javascript on client side

Community
  • 1
  • 1
rahul
  • 7,573
  • 7
  • 39
  • 53
1
document.getElementById('loadfile').addEventListener('change', checkFile, false);

function checkFile(e) {
    var file_list = e.target.files;
    for (var i = 0, file; file = file_list[i]; i++) {
        var fileExtension = file.name.split('.')[file.name.split('.').length - 1].toLowerCase();
        var iConvert = (file.size / 1024).toFixed(2);

        txt = "File type : " +fileExtension + "\n";
        if(file.size > (1024 * 1024)){
            txt += "Size: " + (file.size / (1024*1024)).toFixed(2) + " MB \n";
        } else {
        txt += "Size: " + (file.size / 1024).toFixed(2) + " KB \n";
        }
        alert(txt);
    }
}

see filddle

Harish Singh
  • 3,359
  • 5
  • 24
  • 39
0

IE up to version 9 does not support the file API which is needed to get the file size. IE10 does not support file size.

Beat Richartz
  • 9,474
  • 1
  • 33
  • 50
0

IE doesn't support File API

source : https://github.com/blueimp/jQuery-File-Upload/issues/147

have to use an ActiveX control to perform this action

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");
}

source: http://www.sencha.com/forum/showthread.php?196859-File-Upload-Field-IE-Safari-Opera-fileInput-error.&s=b124834725ae363759158268d91ac32c

Mahmoud Farahat
  • 5,364
  • 4
  • 43
  • 59
  • 7
    I get "Automation server can't create object" trying to run that in a jquery onchange function. – Will May 22 '13 at 06:40