I have a force download that has headers so I obviously cant send a header to redirect after download. I need it to redirect after the download window pops up, and have tried a billion and one things and nothing has worked. Any ideas?
This is what I got:
Force download:
<?php
$filename = $_GET['file'];
// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
// addition by Jorg Weske
$file_extension = strtolower(substr(strrchr($filename,"."),1));
if( $filename == "" )
{
echo "<html><title>Download</title><body>ERROR: download file NOT SPECIFIED. USE force-download.php?file=filepath</body></html>";
exit;
} elseif ( ! file_exists( $filename ) )
{
echo "<html><title>Download</title><body>ERROR: File not found. USE force-download.php?file=filepath</body></html>";
exit;
};
switch( $file_extension )
{
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
case "txt": $ctype="text/txt"; break;
default: $ctype="application/force-download";
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
?>
Form thats sending the download:
else
{
if ($_GET['action'] == checkout)
{
$result = mysql_query("SELECT * FROM data WHERE realname='{$issue}'") or die(mysql_error());
$row = mysql_fetch_array( $result ); //set $row to result
$id = $row['id'];
echo "<b>Are you sure you want to check out<b> " . $issue . "?<br>No one else will be able to edit this item while you have it checked out!<br>";
echo "<form method=post action=force-download.php?file=." . $issue . "><INPUT TYPE=RADIO NAME=out VALUE=out>Check Out! <INPUT TYPE=HIDDEN NAME=out VALUE=out><INPUT TYPE=SUBMIT VALUE=submit></form>";
$_checked = str_replace("<", "", $_POST['out']);
mysql_query("UPDATE data SET status='{$_POST['out']}' WHERE id='$id'") or die(mysql_error());
mysql_query("UPDATE data SET user='{$_SESSION['username']}' WHERE id='$id'") or die(mysql_error());
//redirect
}
}