Redirect after download

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am writing a file download system and I need to be able to do a redirect after the download is finished.

Basically, the user will be presented with a simple HTML page that contains a link to download the file (href="/download.php?fileid=143"). I have the code to send the file working just fine, but I can not figure out how to do a redirect after the download is complete. I have spent the last hour searching the archives, and the closest I have found is:

http://marc.theaimsgroup.com/?l=php-general&m=106128750620349&w=2

But I can't seem to find a way to actually do a Location style redirect. Even static HTML does not display the way one would expect. Using a small text file to download, I can "view source" from NS and see the everything that was sent to the browser, and everything is there (the ---Boundary(s), the text file, and the simple HTML line).

So my question is: How can I perform a redirect after the file has been sent.

Thanks,

Justin

Here is a snippit of download.php (send_file() was found reading the comments to the fread function in the PHP documention):

header("Content-Type: multipart/mixed; boundary=\"-Boundary-12399\"");

if(!send_file($file)) {
die("File transfer failed!");
exit;
}else{
print("\n");
print("---Boundary-12399\r\n");
print("Content-Type: text/html\r\n");
print("\r\n");
print "<html><head><title>Success</title></head><body><b>File transfer s
uccessful!</b></body></html>";
print("\r\n---Boundary-12399\r\n");
print("\r\n");
exit;
}


function send_file($file) {
// read file and send to user
$status = FALSE;
if ( (!is_file($file['filelocation'])) or (connection_status()!=0) ) return(FALSE);
print("---Boundary-12399\r\n");
print("Content-type: application/octet-stream\r\n");
print("Content-Disposition: inline; filename=\"" . $file['filename'] . "\"\r\n");
print("Content-length: " . $file['filesize'] . "\r\n");
print("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y") ) ) . " GMT\r\n");
print("Last-Modified: " . gmdate("D, d M Y H:i:s")." GMT\r\n");
//print("Cache-Control: no-cache, must-revalidate\r\n");
//print("Pragma: no-cache\r\n");
if ($fh = fopen($file['filelocation'], 'rb')) {
while(!feof($fh) and (connection_status()==0)) {
print(fread($fh, 1024*8));
flush();
}
$status = (connection_status()==0);
fclose($fh);
}
return($status);
}


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux