File download (header) problem.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bsprogs
Forum Newbie
Posts: 21
Joined: Mon Apr 23, 2007 1:07 am

File download (header) problem.

Post by bsprogs »

I've got a file hosting website that has been working great for the 3000 files that have been uploaded by my members.
This morning I discovered that once you click on the download link, the file will download, but you can not go back to the website until your download is complete.
The apache server is not limiting the number of connections per IP (it's set at 50 right now)
Here is the main part of the code I'm using. Everything works and downloads great.

Code: Select all

header("Pragma: public");
		header("Expires: 0");
		header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
		header("Cache-Control: private",false);
		header('Content-Type: ' . $fileDownloader->mime_get_type($file));
		header('Content-Disposition: attachment; filename="' . $v_name . '"');
		header("Content-Transfer-Encoding: binary\n");
		header("Content-Length: ". filesize($file));
		readfile($file);
Being that everything else works great, I'm guessing this is a PHP header problem.
Once the download is complete or canceled, the page loads no problem.

Do you guys think this is a header problem?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Does this happen in a particular browser, or many? Which ones?
bsprogs
Forum Newbie
Posts: 21
Joined: Mon Apr 23, 2007 1:07 am

Post by bsprogs »

Sorry, it has happened in IE7, FireFox 2, Opera 9 and the new Safari.
I'm running WinXP Pro SP2.
However, I've had reports from a few linux users that they're getting the same problem in FF.
bsprogs
Forum Newbie
Posts: 21
Joined: Mon Apr 23, 2007 1:07 am

Post by bsprogs »

I just did another test and while downloading in FireFox I couldn't load my site in FireFox but I could in IE7.
So the browser I'm using when I load the page to download the file can not be used to navigate the website, however a different browser will navigate the website.
So I'm pretty sure it is a header issue.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Can you compare the headers you think are being sent with the headers the browsers are receiving?
bsprogs
Forum Newbie
Posts: 21
Joined: Mon Apr 23, 2007 1:07 am

Post by bsprogs »

Is this what you're looking for? I haven't worked much with headers other than using them to change page location and download files.
Date: Sat, 21 Jul 2007 13:39:48 GMT
Server: Apache/1.3.37 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a PHP-CGI/0.1b
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
X-Powered-By: PHP/5.2.2
Keep-Alive: timeout=60, max=490
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The response headers you just posted are completely different from the headers you coded.
bsprogs
Forum Newbie
Posts: 21
Joined: Mon Apr 23, 2007 1:07 am

Post by bsprogs »

feyd wrote:The response headers you just posted are completely different from the headers you coded.
I noticed it is the same header before and after the download is clicked. I'm using the FireFox WebDeveloper 1.1.4 plug-in to get the header information.

I tried starting the download, then clicked to get the header information but it freezes and crashed FF

Even after running the download script, here is the output
Date: Sat, 21 Jul 2007 21:58:44 GMT
Server: Apache/1.3.37 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a PHP-CGI/0.1b
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
X-Powered-By: PHP/5.2.2
Keep-Alive: timeout=60, max=498
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html

200 OK
Is there a way I can get the header info printer on page load using PHP?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

get_headers() may be of interest.
bsprogs
Forum Newbie
Posts: 21
Joined: Mon Apr 23, 2007 1:07 am

Post by bsprogs »

Here we go:



HTTP/1.1 200 OK
Date: Sun, 22 Jul 2007 19:20:32 GMT
Server: Apache/1.3.37 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a PHP-CGI/0.1b
Cache-Control: must-revalidate, post-check=0, pre-check=0, private
Content-Disposition: attachment; filename="Lotus_Website_Project.zip"
Content-Transfer-Encoding: binary
Expires: 0
Pragma: public
X-Powered-By: PHP/5.2.2
Content-Length: 71035
Keep-Alive: timeout=60, max=494
Connection: Keep-Alive
Content-Type: application/zip
bsprogs
Forum Newbie
Posts: 21
Joined: Mon Apr 23, 2007 1:07 am

Post by bsprogs »

I tried changing most of the header options to est out different combinations but still no luck. I also tried nearly everything from php.net as well.
bsprogs
Forum Newbie
Posts: 21
Joined: Mon Apr 23, 2007 1:07 am

Problem Solved

Post by bsprogs »

Well, I think I may have solved my own issue.

It turns out this problem is a hostage situation.

The header and readfile functions hold the php session hostage until the readfile function is done.

Problem solved.
Post Reply