I have written a pair of scripts that are supposed to work together to
display an index of files and then, upon the user choosing the files (with
checkboxes on an HTML form submitted to itself), tar/gzip the file and
send it to them.
To this end the first script performs an exec() call and generates the
archive (it's a random number but we'll call it foo.bar.tar.gz) and then
writes a META tag into the page after it submits the HTML form to itself:
<META HTTP-EQUIV="Refresh"
Content="2;URL=http://server.tld/path/to/sendprogram.php?
archive=foo.bar.tar.gz">
(all on one line of course).
The second script takes in the parameter, sets the headers and tries to
send the file:
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="foo.bar.tar.gz"');
header('Content-Length: '. filesize($_GET['archive']);
if ( $file = fopen($_GET['archive'], 'rb') )
{
while ( !feof($file) and (connection_status() == 0) )
{
print(fread($file, 8192));
flush();
}
}
fclose($file);
unlink($_GET['archive']);
(note the above code was taken from user submissions within the online
manuals at
www.php.net)
Now the odd part:
If I'm using IE, this works just fine. I submit the form, wait a few
moments, and then the file transfer dialog box pops up and begins the
download. The file is fine and contains no errors.
If I'm using Netscape 7.1, I still get the file transfer dialog box but
then it never transfers the file. I get a zero byte file. If I remove
the unlink() from the second script, it works (but leaves behind the
archive of course).
Does anyone have any idea why this might be happening and what the right
way or workaround might be?
Thanks