IE problem w/ header() for downloads
Posted: Wed Jul 02, 2003 3:26 pm
I wrote a script to hide actual file locations from the user. In order to download a file, the user has to go to download.php?file=123 (whatever the file number is). That page checks to make sure they are logged in, have access to the file, etc.
It works great, for the most part. When I try it on my local machine (see below for server info), it works great. When I try it on the actual server, it will not work correctly in ie for windows. All the other browsers are fine, though.
Here's some sample code:
Here's the server situation: we have a server running php 4.2.2 with apache 2.0.40 on redhat 8. I have a local test machine running the same stuff, but I have a slightly more up-to-date system (I run up2date more frequently). There is a chance our php/apache versions are not identical, but nothing major. I've gone through a diff of the httpd.conf files, and the php.ini files but can't find anything that seems like it should cause it. I've read the comments on the header() man page, but none of those seemed to help. What really confuses me is that it works with ie off my machine, but not the server. Any ideas?
It works great, for the most part. When I try it on my local machine (see below for server info), it works great. When I try it on the actual server, it will not work correctly in ie for windows. All the other browsers are fine, though.
Here's some sample code:
Code: Select all
<?php
// Make sure file exists and open it up here
header("Cache-Control: public\n");
header("Pragma: no-cache\n");
header("Content-type: $type\n");
header("Content-disposition: attachment; filename="$obj->Filename"\n");
header("Content-transfer-encoding: $encoding\n");
header("Content-Length: $size\n");
header("Connection: close\n");
// Read the actual file, 4k at a time
while (!feof($fp)) {
$buffer = fread($fp, 4096);
print $buffer;
}
fclose($fp);
?>