Page 1 of 1

File download (header) problem.

Posted: Sat Jul 21, 2007 12:11 am
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?

Posted: Sat Jul 21, 2007 12:13 am
by feyd
Does this happen in a particular browser, or many? Which ones?

Posted: Sat Jul 21, 2007 12:35 am
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.

Posted: Sat Jul 21, 2007 12:56 am
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.

Posted: Sat Jul 21, 2007 7:01 am
by feyd
Can you compare the headers you think are being sent with the headers the browsers are receiving?

Posted: Sat Jul 21, 2007 8:57 am
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

Posted: Sat Jul 21, 2007 9:54 am
by feyd
The response headers you just posted are completely different from the headers you coded.

Posted: Sat Jul 21, 2007 3:14 pm
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?

Posted: Sat Jul 21, 2007 9:44 pm
by feyd
get_headers() may be of interest.

Posted: Sun Jul 22, 2007 2:22 pm
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

Posted: Wed Jul 25, 2007 1:48 pm
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.

Problem Solved

Posted: Thu Jul 26, 2007 4:29 pm
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.