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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.