0

以下のコードはhtml5uploaderからのものであり、IE 10を除くすべてのブラウザーで正常に動作します。IEが検出され、ドロップされたファイルが読み取られる関数を含めるように最善を尽くしましたが、IEでこれを動作させることができませんでした。

以下の関数のコードを変更してInternetExplorer10を含めるにはどうすればよいですか?

ここに完全なJavascriptコード。ここにアップローダーへのリンク。

    // Firefox 3.6, Chrome 6, WebKit
    if(window.FileReader) { 

        // Once the process of reading file
        this.loadEnd = function() {
            bin = reader.result;                
            xhr = new XMLHttpRequest();
            xhr.open('POST', targetPHP+'?up=true', true);
            var boundary = 'xxxxxxxxx';
            var body = '--' + boundary + "\r\n";  
            body += "Content-Disposition: form-data; name='upload'; filename='" + file.name + "'\r\n";  
            body += "Content-Type: application/octet-stream\r\n\r\n";  
            body += bin + "\r\n";  
            body += '--' + boundary + '--';      
            xhr.setRequestHeader('content-type', 'multipart/form-data; boundary=' + boundary);
            // Firefox 3.6 provides a feature sendAsBinary ()
            if(xhr.sendAsBinary != null) { 
                xhr.sendAsBinary(body); 
            // Chrome 7 sends data but you must use the base64_decode on the PHP side
            } else { 
                xhr.open('POST', targetPHP+'?up=true&base64=true', true);
                xhr.setRequestHeader('UP-FILENAME', file.name);
                xhr.setRequestHeader('UP-SIZE', file.size);
                xhr.setRequestHeader('UP-TYPE', file.type);
                xhr.send(window.btoa(bin));
            }
            if (show) {
                var newFile  = document.createElement('div');
                newFile.innerHTML = 'Loaded : '+file.name+' size '+file.size+' B';
                document.getElementById(show).appendChild(newFile);             
            }
            if (status) {
                document.getElementById(status).innerHTML = 'Loaded : 100%<br/>Next file ...';
            }
        }
4

1 に答える 1

1

問題が解決されたとしても、おそらくこれは他の人を助けることができます:

1)ブラウザをIE10に強制するようにしてください:<meta http-equiv="X-UA-Compatible" content="IE=edge">

2) IE用reader.readAsBinaryString(file);以外は使用しないreader.readAsDataURL(file);

3)XHRオブジェクトをで送信し、xhr.send使用しないでくださいbtoa(実行するだけですxhr.send((bin));

4)一般に、コードをすべてのブラウザーと互換性があるようにするには、if (navigator.appName === "Microsoft Internet Explorer") { ... }ブラウザーごとに異なるターゲットでXHRオブジェクトを使用して開きます(このように:)。これxhr.open('POST', targetPHP+'?up=true&browser=IE', true);は、PHPによって処理が異なるためです。

すべてがここで説明されています:IEをサポートするためにhtml5uploaderで使用されるXmlHttpRequestまたはFileAPIを変更するにはどうすればよいですか?

于 2013-09-19T09:01:38.593 に答える