Oziam Posted November 3, 2010 Share Posted November 3, 2010 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???? Quote Link to comment https://forums.phpfreaks.com/topic/217616-redirect-after-file-download-problem/ Share on other sites More sharing options...
MasterACE14 Posted November 3, 2010 Share Posted November 3, 2010 is it possible that the 'print' before the header() is breaking the script? print stream_get_contents($fp) Quote Link to comment https://forums.phpfreaks.com/topic/217616-redirect-after-file-download-problem/#findComment-1129727 Share on other sites More sharing options...
PFMaBiSmAd Posted November 3, 2010 Share Posted November 3, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/217616-redirect-after-file-download-problem/#findComment-1129728 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.