Jump to content

redirect after file download problem


Oziam

Recommended Posts

I am using a script for users to download a file, however after the download I want to be able to

redirect the user or display a message etc... but I cannot get it to work.

 

My download code is below;

 

if($do_download){

$filename = 'file.zip';
$itemfile = ('/abc/123/htdocs/bin/'.$filename);
$filelength = filesize($itemfile);

$fp = @fopen($itemfile, "rb");

ob_start();
  Header("Pragma: public");
  Header("Expires: 0");
  Header("Cache-control: private");
  Header("Content-Type: application/x-zip-compressed");
  Header("Content-Transfer-Encoding: binary");
  Header("Content-Length: $filelength");
  Header("Accept-Ranges: bytes");
  Header('Content-Disposition: attachment; filename="'.$filename.'"');
  Header("Connection: close");
ob_end_clean();
  while(!feof($fp)){
  print stream_get_contents($fp); // for PHP 5+ else use fread
}
fclose($fp);

header('Location: page2.php');
}

 

It doesn't seem to matter what I do whether a redirect or just an echo command nothing continues after the file is downloaded????

Link to comment
https://forums.phpfreaks.com/topic/217616-redirect-after-file-download-problem/
Share on other sites

The ONLY thing the code in your download file can do is output the headers() followed by the file data. Anything else it does will become part of the downloaded data.

 

Anything else you want to do must be accomplished on the page where the link to the download was located.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.