class DownloadGenerat or {
var $fullFilePath;
function DownloadGenerat or($fullFilePat h) {
$this->fullFilePath = $fullFilePath;
}
function &generateForceD ownloadHeaders( $fullFilePath = '') { //
STATIC VOID METHOD
$file = ($this->fullFilePath ) ? $this->fullFilePath : $fullFilePath;
if (if_file($file) ) {
$filesize = @filesize($file );
header("Content-Disposition: attachment; filename=$file" );
header('Content-Type: application/octet-stream');
header('Content-Type: application/force-download');
header('Content-Type: application/download');
header('Content-Transfer-Encoding: binary');
header('Pragma: no-cache');
header('Expires : 0');
@set_time_limit (600);
readfile($file) ;
}
}
}
[/PHP]
I am trying to "have my cake and eat it too", so to speak. I want to
do a forced download of a file using readfile() and manipulating the
headers; but at the exact same time I need to redirect to another
page, the page that says "hey everything is cool" success message and
display the rest of the application.
Right now what it does is that it does force a download (in Mozilla)
but your window is blank. The user has no ability to navigate any
further and is forced to close and re-open their browser and start all
over again, definitely not an option.
How can I use readfile() to force a download of a file, yet at the
same time display a screen indicating the rest of the application?
The idea I thought up was this:
[PHP]
foreach ($_REQUEST as $key => $val) if (!isset(${$key} )) ${$key} =
$val; // RETRIEVE ALL PASSED VARS
if ($forceDownload ) { // HANDLE FORCED DOWNLOAD
$dlGen =& new DownloadGenerat or($fullFilePat h);
$dlGen->generateForceD ownloadHeaders( );
echo "<a href=\"index.ph p" . $dlGen->generateQueryS tring() .
"\">Continu e</a>\n";
$dlGen = null;
}
[/PHP]
This resulting from
index.php?force Download=1&full FilePath=/tmp/images/blah.jpgThanx
Phil