A JM Posted December 31, 2009 Share Posted December 31, 2009 I'm successfully able to export a file but am having a problem with a redirect after the files is downloaded, can this be done? am I just trying to implement it incorrectly? ... //Print the iif file header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"invoice.txt"); header("Pragma: no-cache"); header("Expires: 0"); print $data; exit; //after exporting return to main page $insertGoTo = "home.php?"; header(sprintf("Location: %s", $insertGoTo)); Any help would be appreciated. Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/186802-re-direct-problem/ Share on other sites More sharing options...
premiso Posted December 31, 2009 Share Posted December 31, 2009 You do two things wrong. A: you are printing $data, so header will not work after that. B. you exit the script before you get to your redirect. As well, you cannot do a redirect here as far as I know. Your best bet is when a download is called you open it in a new window, this way the user can just close the window and be back to where they were. As given the headers you sent to let the user download that file, you cannot do anytype of a redirect, as far as I know. Quote Link to comment https://forums.phpfreaks.com/topic/186802-re-direct-problem/#findComment-986454 Share on other sites More sharing options...
A JM Posted December 31, 2009 Author Share Posted December 31, 2009 I appreciate the response premiso. Sorry, I forgot to comment out the exit; which I have been doing when running in production. A: you are printing $data, so header() will not work after that. How else would I do this, echo? Thanks, Quote Link to comment https://forums.phpfreaks.com/topic/186802-re-direct-problem/#findComment-986466 Share on other sites More sharing options...
premiso Posted December 31, 2009 Share Posted December 31, 2009 No, after any output is sent to the browser you cannot run any headers, as headers must be before the body of the document. As I suggested, you can have the link open a new window, or open a popup in javascript to dish the file. Other than that I do not know what other ways. But what you are trying to do is not possible, at least as far as I know. Quote Link to comment https://forums.phpfreaks.com/topic/186802-re-direct-problem/#findComment-986471 Share on other sites More sharing options...
PFMaBiSmAd Posted December 31, 2009 Share Posted December 31, 2009 Anything you output after the file data will be appended to the file. Quote Link to comment https://forums.phpfreaks.com/topic/186802-re-direct-problem/#findComment-986473 Share on other sites More sharing options...
A JM Posted December 31, 2009 Author Share Posted December 31, 2009 Thanks for the info. I'll work on changing it. Quote Link to comment https://forums.phpfreaks.com/topic/186802-re-direct-problem/#findComment-986477 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.