Jump to content

Recommended Posts

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,

 

Link to comment
https://forums.phpfreaks.com/topic/186802-re-direct-problem/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/186802-re-direct-problem/#findComment-986454
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/186802-re-direct-problem/#findComment-986471
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.