473,795 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2468
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
Bouffa:
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.

--
Jock

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 :

<?php
$filename=basen ame($file_to_do wnload);
$file_extension = strtolower(subs tr(strrchr($fil ename,"."),1));
switch( $file_extension ) {
case "mp3": $ctype="audio/mpeg"; break;
case "mpg":$ctype="v ideo/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="applica tion/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='Conten t-Disposition: attachment; filename="'.$fi lename.'";';
header($header );
header("Content-Transfer-Encoding: binary");
$size=filesize( $file_to_downlo ad);
//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($ra nge, "-", $range);
$size2=$size-1;
header("Content-Range: $range$size2/$size");
$new_length=$si ze2-$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("$_fi le","r");
//seek to start of missing part
fseek($fp,$rang e);
//start buffered download
while(!feof($fp )){
//reset time limit for big files
set_time_limit( );
print(fread($fp ,1024*8));
flush();
}
fclose($fp);
exit;

May 30 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8180
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 How should i Proceed ?? pls help me
1
1528
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 on the dev versus the live sites, because I am working on it... This is fine, as I have a routine that downloads the OCX file, but MS standard only downloads a later version. Hence, if I work in the dev site, then switch to live, it still uses the...
16
2257
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. So I've adopted the approach of having two projects share the same set of files. In my case, I have two similarly named projects: DataObjects DataObjectsCF The former is for the Desktop app and the latter is for the Compact Framework.
1
5401
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 completely/succsessfully on the client's computer before updating some metadata on the server (file downloaded date for instance) However, All examples i have tried, and all examples I have found that other people says works - doesn't work for me :-(
2
2354
by: comp.lang.php | last post by:
class ReportGenerator { function ReportGenerator() {} /** * Generate the HTTP headers necessary for this file type. Can be called statically *
9
3268
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 : From.cs and Form.Designer.cs, and get thoses file "grouped" in the Solution explorer under the main Form.cs file ?
2
1937
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 applications. Recently, I had some problems reading DVDs that I had recently burned, reading them with the same DVD device that burned them. So I wrote a quickie verification program that simply attempts to binary read all files on the disk.
3
1395
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?
1
2085
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 options, browsing history, settings, view objects, place....(i have IE7, so to get to them is a little different than IE6, etc.). Anyway, I took his "wise and sage" advice and deleted all of my DOWNLOADED PROGRAM FILES, while I was doing my other...
1
6623
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 that contains the ActiveX, the ActiveX is loaded and the website works fine. However if I run a web test created using VS Team Suite or run a Load test of the same web test within VS, the ActiveX is not loaded on the page and this warning keeps...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10214
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.