Multiple file upload from archive supporting RANGE requests
Sometimes it is useful not to save a bunch of files on any hosting, but to use only one archive file. But there is a problem of access to a specific file in the archive. I bring to your attention a PHP script that allows you to download part of the archive file as a whole file. Supports reloading through RANGE requests. An archive, in this case, is simply a gluing of many files. The script is currently tested with the Flashget download manager.
In order to download a specific file, it is enough to indicate its offset in the archive file, the size and name of this file as follows:
htp: //address/script_name.php? Name = filename & offset = 3000 & size = 100
As a result, the user of such a link will receive a file of 100 bytes in size named filename, which is located at an offset of 3000 archive file.
In order to download a specific file, it is enough to indicate its offset in the archive file, the size and name of this file as follows:
htp: //address/script_name.php? Name = filename & offset = 3000 & size = 100
As a result, the user of such a link will receive a file of 100 bytes in size named filename, which is located at an offset of 3000 archive file.
Copy Source | Copy HTML- $offset = isset($_REQUEST['offset']) ? (int) $_REQUEST['offset'] : 0;
- $size = isset($_REQUEST['size']) ? (int) $_REQUEST['size'] : false;
- $name = isset($_REQUEST['name']) ? urlencode($_REQUEST['name']) : 'download.bin';
-
- if (empty($size)) die;
-
- // link to archive file
- $url = 'http://archive_file_url';
-
- @set_time_limit(0);
-
- $range_size = $size;
- $range_offset = $offset;
-
- if (isset($_SERVER['HTTP_RANGE'])) {
- if (preg_match('/^bytes=(\d+)\-$/', $_SERVER['HTTP_RANGE'], $m)) {
- $range_offset+=$m[1];
- $range_size-=$m[1];
- } elseif (preg_match('/^bytes=(\d+)\-(\d+)$/',$_SERVER['HTTP_RANGE'], $m)) {
- $range_offset+=$m[1];
- $range_size=$m[2]-$m[1]+1;
- } else {
- // TODO (aig): support other ranges if needed
- die();
- }
- header('HTTP/1.1 206 Partial Content');
- } else {
- header('HTTP/1.1 200 Ok');
- }
-
- $range = ($range_offset)."-".($range_offset+$range_size-1);
- header("Content-Type: application/octet-stream");
- header("Accept-Ranges: bytes");
- header("Content-Length: $range_size");
- header('Content-Disposition: attachment; filename="' . $name . '";');
-
- $ch = curl_init();
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch,CURLOPT_RANGE,$range);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,0);
- curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
- curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3');
- curl_exec($ch);
- curl_close($ch);
- ?>
-