Jump to content

Writing an excel file or redirecting the user, but not both. Help!


lamajlooc

Recommended Posts

Hi,
So I'm writing a script that reads various data from the DB, writes and Excel file and (hopefully) redirects the user to a confirmation page after that's done.  The problem is that it either writes the files fine and doesn't redirect or redirects fine but won't write the file.  I'm using header and I'm getting a conflict.

Here's the code:
if ($header!="" && $data!=""){
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$title.xls");
header("Pragma: no-cache");
header("Expires: 0");
//header("Location: exportresult.php"); This is commented out so the file writes.
print "$header"."$data";
} else {
header("Location: exportproblem.php");
}

I was thinking about using fwrite to write the file but that seems very cumbersome.  Any other ideas?
Link to comment
Share on other sites

Thanks for posting this question.  I learned something as a result of it too.

I've been wondering how to create a file on the fly to be downloaded without having to save the file to the server first.  I thought there had to be a way.
Link to comment
Share on other sites

  • 1 year later...
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.