File: download.html

Recommend this page to a friend!
  Classes of Chi Hoang  >  Mass Downloader  >  download.html  >  Download  
File: download.html
Role: Auxiliary data
Content type: text/plain
Description: html file
Class: Mass Downloader
Serve local server or remote files for download
Author: By
Last change:
Date: 4 years ago
Size: 3,923 bytes
 

Contents

Class file image Download
<!-- /* 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>

For more information send a message to info at phpclasses dot org.