I have a PHP4 script that I'm using to allow users to download files. Users click a download button and it takes them to file_download.php with the following script which queries the DB on the file's ID and then uses the "Content-Disposition: attachment" method to prompt the user's browser to open a "save as" dialog box:
<?php
ob_start();
global $INCLUDEPATH,$myReferer;$SIMAGEPATH;
include "../includes/site.inc";
include "$INCLUDEPATH/time.inc";
include "$INCLUDEPATH/process.inc";
$now=tdt("nt");
myDBconnect();
// DEFINE GET VARIABLES
foreach($_GET as $thisvar => $thisval) { $$thisvar=$thisval; }
if(isset($f_id)) {
// IF THE ID IS SET, DOWNLOAD THE FILE
$query = "SELECT f_filename, f_size, s_thefile, s_thetype FROM fs_files INNER JOIN fs_stored ON s_f_id=f_id WHERE s_id = '$f_id'";
$result = mysql_query($query);
list($f_filename, $f_size, $s_thefile, $s_thetype) = mysql_fetch_array($result);
header("Content-length: $f_size");
header("Content-type: $s_thetype");
header("Content-Disposition: attachment; filename=$f_filename");
echo $s_thefile;
myDBdisconnect();
ob_end_flush();
header("Location: $SECUREPATH/fileshare/file_view.php?uid=" . $u_id . "&did=" . $d_id . "\n\n");
exit;
}
?>
This works for most browsers: they hit this page and the "Content-Disposition: attachment" command prompts the browser to give the user a "save as" dialog box so they can save the file to their computer.
I have seen references to bugs in IE 4.01 and 5.5(SP1). But it is also not working in NS 7.01. Has anyone seen a workaround for this problem in NS7? When a NS7 user hits the download page, it stays stuck on the page (instead of obeying the header("Location") command that returns the user to the file page). If you try and view source on the page, it will prompt you to download the contents of file_download.php. Very strange.
Any idea why this method doesn't work in NS7? Is there a better method than using the "Content-Disposition" method? Or a workaround for NS7?