470,570 Members | 2,252 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,570 developers. It's quick & easy.

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

Hello everyone,

I suppose you all know force-download scripts. The problem is that
these scripts don't allow files to be splitted when downloading them
via a download manager.
I've found a solution to enable download resuming, but now, it remains
the splitting problem. Does anyone have any idea ?

May 28 '06 #1
3 2285
For apache servers, use
implode('::', apache_request_headers());
It will get each request headers from apache.

Download managers will send this request:
Range: bytes=xxxxx-yyyyy
Where xxxxx is the start position, and yyyyy is the end position.

Some download managers will send this request:
Range: bytes=xxxxx-
This means start position is xxxxx and so on.

If it has no matches, send it all.

If the match was found, send this header.
header('HTTP/1.1 206 Partial content');
else send this.
header('HTTP/1.1 200 OK');

Use substr to split the file content and send
header('Content-Length: ' . strlen($content));
// The substred content.

Hope this helps.

May 28 '06 #2
I suppose you all know force-download scripts.

I don't believe I do. I don't believe there's any such things. Yes,
there's things that might be called force-download scripts, but that
doesn't really make them scripts that force downloads, does it?

The success, if you can call it that, of the kind of script I think
you're talking about rests on a set of ifs: if the user-agent is
configured this way, then... if the user-agent is configured that way,
then... There's too many conditions to be met for me to be comfortable
with 'force'.

Also, alarm bells should ring when you see that such scripts are most
sucessful if they misrepresent the data, by which I mean having
Content-Types that don't tell the MIME type.


May 28 '06 #3
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 :

$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: 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");
//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);
header("Content-Range: $range$size2/$size");
header("Content-Length: $new_length");
//if not, download whole file
} else {
header("Content-Range: bytes 0-$size2/$size");
header("Content-Length: ".$size2);
//open the file
//seek to start of missing part
//start buffered download
//reset time limit for big files

May 30 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by dharmesh Gupta | last post: by
1 post views Thread by Ruskin | last post: by
16 posts views Thread by Robert W. | last post: by
2 posts views Thread by comp.lang.php | last post: by
1 post views Thread by =?Utf-8?B?UnVzc2VsbA==?= | last post: by
1 post views Thread by =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.