Reply to Re: How to allow downloaded files to be splitted when using a force-download script ?

Your name:

Reply:


Posted by Bouffa on 05/30/06 17:27

the DtTvB
>Hope this helps.

I'm afraid no :(

The apache server (1.33) of my hoster doesn't recognize neigther
apache_request_headers nor getallheaders function !

So I tried to use the $_ENV['HTTP_RANGE'] to read the header sent by
the download manager. I put some lines to store the headers. The first
time the file is downloaded, there is no header http_range recieved by
the script, so no splitted parts. When I pause then resume the
download, the header Range: bytes=xxxxx- is sent, so the script sends
the rest of the file.
Here is my code :

<?php
$filename=basename($file_to_download);
$file_extension = strtolower(substr(strrchr($filename,"."),1));
switch( $file_extension ) {
case "mp3": $ctype="audio/mpeg"; break;
case "mpg":$ctype="video/mpeg"; break;
case "avi": $ctype="video/x-msvideo"; break;
case "wmv": $ctype="video/x-ms-wmv";break;
case "wma": $ctype="audio/x-ms-wma";break;
default: $ctype="application/force-download";
}

//Begin writing eaders
header("Pragma: public");
header("Expires: 0");
header("Cache-Control:");
header("Cache-Control: public");
header("Content-Description: File Transfer");
//Use the switch-generated Content-Type
header("Content-Type: $ctype");
$header='Content-Disposition: attachment; filename="'.$filename.'";';
header($header );
header("Content-Transfer-Encoding: binary");
$size=filesize($file_to_download);
//check if http_range is sent by browser (or download manager)
if(isset($_ENV['HTTP_RANGE'])) {
list($a, $range)=explode("=",$_ENV['HTTP_RANGE']);
//if yes, download missing part
str_replace($range, "-", $range);
$size2=$size-1;
header("Content-Range: $range$size2/$size");
$new_length=$size2-$range;
header("Content-Length: $new_length");
//if not, download whole file
} else {
$size2=$size-1;
header("Content-Range: bytes 0-$size2/$size");
header("Content-Length: ".$size2);
}
//open the file
$fp=fopen("$_file","r");
//seek to start of missing part
fseek($fp,$range);
//start buffered download
while(!feof($fp)){
//reset time limit for big files
set_time_limit();
print(fread($fp,1024*8));
flush();
}
fclose($fp);
exit;

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация