lamajlooc Posted November 3, 2006 Share Posted November 3, 2006 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? Quote Link to comment Share on other sites More sharing options...
toplay Posted November 4, 2006 Share Posted November 4, 2006 It looks like you're forcing a download of a file. If the file has already been written to disk, you can use readfile() to read and output to buffer (for download).I don't think you can do both download and redirect, it's one or the other. Quote Link to comment Share on other sites More sharing options...
doni49 Posted November 4, 2006 Share Posted November 4, 2006 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. Quote Link to comment Share on other sites More sharing options...
lamajlooc Posted December 4, 2007 Author Share Posted December 4, 2007 Thanks for the help. Quote Link to comment 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.