PHP outputting a file for download.

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
EoN
Forum Newbie
Posts: 22
Joined: Thu Oct 11, 2007 5:57 am

PHP outputting a file for download.

Post by EoN »

Hi guys,

I've recently moved my web application to a new server, and everything is humming now except for two unusual issues that I was hoping someone could help shed some light on.

1. My web application outputs a file for download using the following code:

Code: Select all

header('HTTP/1.1 200 OK');
header('Date: ' . date("D M j G:i:s T Y"));
header('Last-Modified: ' . date("D M j G:i:s T Y"));
header("Content-Type: application/octet-stream");
header("Content-Length: " . (string)(filesize($fileHandle)) );
header("Content-Transfer-Encoding: Binary");
header('Content-Disposition: attachment; filename="'.$fileName.'"' );
readfile($fileHandle); 
On my previous server, the browser's download dialog would display the 'total file size' (ie "Downloading X bytes of TOTAL_SIZE").

On my new server it doesn't display the total filesize, and thus doesn't display the estimated time. Does anyone know what might cause this total filesize to not be picked up? And how can it be corrected?


2. While the file is downloading, any further requests/refreshes on the web site seem to just time out. As soon as the download finishes, I can view the site easily again. I'm guessing this must be some sort of 'one connection per session or per ip' type thing?

If anyone could help, would be much appreciated :)

Regards,
EoN
Post Reply