473,388 Members | 915 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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 2439
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: dharmesh Gupta | last post by:
Hi, i have a program splitted across two files main_prog.cpp idr.cpp my main_prog.cpp accepts a file name a s parameter. i want to capture this file name in a variable and use it in idr.cpp ...
by: Ruskin | last post by:
I have a wee issue, where I have two different web sites; http://dev/home.htm http://live/home.htm On both sites, there is a custom OCX file being used. However, it may be a different version...
by: Robert W. | last post by:
I'm building a solution that has 1 component for the Desktop and 1 component for the Pocket PC. (Though this isn't a mobile question). I have a data library that will be shared on both platforms....
by: Roy | last post by:
Hi, I have a problem that I have been working with for a while. I need to be able from server side (asp.net) to detect that the file i'm streaming down to the client is saved...
by: comp.lang.php | last post by:
class ReportGenerator { function ReportGenerator() {} /** * Generate the HTTP headers necessary for this file type. Can be called statically *
by: TheSteph | last post by:
In VS 2005 Form files are in 3 parts : From1.cs, Form1.Designer.cs and Form1.resx. In VS 2003 there is only one ".cs files". How can I split my old VS2003 ".cs files" files in 2 files :...
by: zacks | last post by:
I use some shareware CD/DVD burning software that has a command line interface version. This allowed me to write my own custom SDK that performs various CD/DVD burning operations from my own VB.NET...
by: caseahr | last post by:
When you create data files and filegroups, you specify a size. My question is -- how do you know how full they are? Is there a stored procedure for that?
by: =?Utf-8?B?UnVzc2VsbA==?= | last post by:
Some sage tech told me, in an online discussion on how to keep my computer clean and working smoothly, that it was ok to delete all of the "downloaded program files" that reside in that internet...
by: =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?= | last post by:
I have already set the Internet Options->Advanced ->Security to "Allow active content to run in files on My Computer" and restarted the browser. If I navigate using the browser to the website...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.