<!-- /* Copyright (C) Chi Hoang - All Rights Reserved
* Unauthorized copying of this file, via any medium is strictly prohibited
* Proprietary and confidential
* Written by Chi Hoang <chibox@gmail.com>, Februar 2016
*/
//-->
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=utf-8">
</head>
<body>
Test
<script>
function createRequestObject() {
var xmlHttp = false;
if (typeof(XMLHttpRequest) != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
if (!xmlHttp) {
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
xmlHttp = new
ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
xmlHttp = false;
}
}
}
return xmlHttp;
}
var xhr=new Array();
function downloadList (fileList, callback) {
i=0;
for (var key in fileList) {
xhr[i]= createRequestObject();
if (xhr[i]) {
xhr[i].open('GET', 'file.php?file='
+key
+'&path='+fileList[key],
true);
xhr[i].responseType = 'arraybuffer';
xhr[i].onreadystatechange = null;
xhr[i].addEventListener( "load", callback, false);
xhr[i].send(null);
}
i++;
}
}
var toDownload = {
'file1': 'path1/',
'file2': 'path2/',
'file3': 'path3/'
};
var target = new Object();
downloadList(toDownload, function (result) {
var contDisposition =
this.getResponseHeader("Content-Disposition");
if (contDisposition !== null) {
var re = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/i;
var m;
if ((m = re.exec(contDisposition)) !== null) {
if (m.index === re.lastIndex) {
re.lastIndex++;
}
var filename=m[1].replace(/"/g,'');
}
if (toDownload[filename]) {
target[filename]=toDownload[filename];
}
var blob = new Blob([this.response], {type:
"application/pdf"});
var link = document.createElement('a');
link.download = filename;
link.href = window.URL.createObjectURL(blob);
link.click();
} else {
var uInt8Array = new Uint8Array(this.response);
var str = String.fromCharCode.apply(null, uInt8Array);
if (toDownload[str]) {
target[str]="this_file_does_not_exist";
}
}
if (Object.keys(target).length ==
Object.keys(toDownload).length) {
console.log(target);
}
});
</script>
</body>
</html>
|