How to get file size from clientside using javascript in IE?

前端 未结 5 922
走了就别回头了
走了就别回头了 2020-12-31 15:03

I used the following methode

HTML


JavaScript

相关标签:
5条回答
  • 2020-12-31 15:18

    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

    0 讨论(0)
  • 2020-12-31 15:32

    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

    0 讨论(0)
  • 2020-12-31 15:34
    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

    0 讨论(0)
  • 2020-12-31 15:42

    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

    0 讨论(0)
  • 2020-12-31 15:42

    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.

    0 讨论(0)
提交回复
热议问题