OK I can get it to download a file perfectly now.
But there is one catch:
Basically I have an auto generated table, and to the right of each file, there's a download button. So I was trying to code it so that each button would have a different filename. In the end, it appears the filename is somehow not being used by the second script when it's run.
Here's the code:
CALLING SCRIPT snippet:
if($x == 4)
{
$thedate = date('l dS of F Y h:i:s A', $row[4]);
print $thedate;
print "<P>";
print $row[4];
print "<P>";
}
if($x == ($cols))
{
$filename = "C:/Program Files/Apache Group/Apache2/TU/Documents/".mysql_result($qr, $i, 1);
$fname = "FILENAME".$i;
$_SESSION['$fname'] = $filename;
// print $_SESSION['$fname'];
// print "<P>";
$fsave = "SAVEAS".$i;
$_SESSION['$fsave'] = mysql_result($qr, $i, 1);
// print $_SESSION['$fsave'];
// print "<P>";
// print $i;
// print "<P>";
$toreturn .="\t<td><CENTER><form method=POST action='download.php?i=$i'><input type=submit value='Download' name='download'></form><form method=POST action='delete.php'><input type=submit value='Delete Me' name='delete'></form></CENTER></td>\n";
}
lastly, the called script:
<?
// secureindex.php - secure page
// session check
if ( isset($_COOKIE['PHPSESSID']) ){
session_start();
} else {
header("Location: /error.php?e=2");
exit();
}//end if
import_request_variables("gP", "i_");
$fname = "FILENAME".$i_i;
$thefile = $_SESSION['$fname'];
print $thefile;
print "<P>";
$savename = "SAVEAS".$i_i;
$saveas = $_SESSION['$savename'];
print $fname;
print "<P>";
print $savename;
if(strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'MSIE')){
// IE cannot download from sessions without a cache
header('Cache-Control: public');
}
$fp = fopen($thefile, 'rb');
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=$saveas"); //tells what to save as
header("Content-Length: ".filesize($thefile));
fpassthru($fp);
exit;
?>