2014-10-01 112 views
0

我試圖從文件輸入控件中獲取文件的大小。 要做到這一點我使用jQuery:Internet Explorer 11獲取文件大小

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

在這工作得很好,除了IE(使用版本11)的任何瀏覽器,但我認爲它應該支持一下文件API嗎? 它說e.files是undefinied

+0

您確定這適用於所有瀏覽器? http://www.html5rocks.com/en/tutorials/file/dndfiles/ – 2014-10-01 06:34:48

+0

http://caniuse.com/#feat=fileapi它至少應該在IE chrome和firefox中工作,這對於這個項目來說非常重要 – Ced 2014-10-01 06:37:31

+0

我的意思是,你確定這段代碼有效嗎? – 2014-10-01 06:38:08

回答

0

它會要求在瀏覽器中啓用ActiveX,請說讓

<!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> 

這ANS在how validate file size using HTML and Javascript on client side

0

的問題是被賦予的是,IE設置他自己進入了版本7兼容模式。