0

I'm trying to get the size of a file from a file-input control. To do this I'm using jquery:

function init() {
    $("#cphInhalt_cphInhalt_file0").bind("change", function() {
        handleFileSelect(this);
    });
}

function handleFileSelect(e) {
    if (e.files[0].size + totalFileSize > 3000000) {
        addNewUpload(e);
        $(e).remove();
        if (getCookie("language") == "German") {
            alert("Die gesamte Dateigröße wurde überschritten");
        } else {
            alert("The total file size has been exceeded");
        }
        return;
    }

In any browser this works fine, except of Internet explorer ( using version 11) , but as I think it should support the File Api right? It says e.files is undefinied

Adrian Forsius
  • 1,437
  • 2
  • 19
  • 29
Ced
  • 1,301
  • 11
  • 30
  • Are you sure this works in all browsers? http://www.html5rocks.com/en/tutorials/file/dndfiles/ – Evan Knowles Oct 01 '14 at 06:34
  • http://caniuse.com/#feat=fileapi it should at least work in IE chrome and firefox, which are mainly important for this project – Ced Oct 01 '14 at 06:37
  • I mean, are you sure this code works? – Evan Knowles Oct 01 '14 at 06:38
  • yes I tried this with chrome and fire fox, the most strange thing is that the code is working in Internet Explorer when I'm running from visual studio, but when I'm calling the page from the server IE suddenly doesn't run the code – Ced Oct 01 '14 at 06:40

2 Answers2

0

It will ask for Enable ActiveX in your browser, please say allow

  <!DOCTYPE html>
    <html>
    <head>
    <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;
     alert(size +" bytes");
    }
    </script>
    </head>
    <body>
    <form name="upload">
    <input type="file" name="file">
    <input type="button" value="Size?" onclick="getSize();">
    </form>
    </body>
    </html>

This ans was given in how validate file size using HTML and Javascript on client side

Community
  • 1
  • 1
Sumeet Patil
  • 422
  • 3
  • 14
0

The problem was, that the IE set himself into a Version 7 compatibility mode.

Ced
  • 1,301
  • 11
  • 30