Page 1 of 1

setting headers & printing content issue

Posted: Tue Jun 03, 2008 3:14 pm
by lefnire
i have a php page with a button that exports a mysql table to csv. the problem is that the actual html page is printed to that csv file right before the mysql content. in otherwords, my csv output looks something like this:

<html><body>bla bla bla</html></body>
col1, col2
cell1, cell2,
cell3, cell4

and it *should* just be the col/cell stuff, without the html.
my hunch is that i'm messing up with the headers somehow, like I'm failing to clear the current output before re-outputing the csv data or something. My header declarations look like this:

Code: Select all

//$out = mysql conversion to csv
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Length: " . strlen($out));
header("Content-type: text/x-csv");
header("Content-Disposition: attachment; filename=$filename");
echo $out;
exit;
and a print_r on $out shows that it's pure mysql output, without any html. the full source is at http://pastebin.com/m11bef0bf

Re: setting headers & printing content issue

Posted: Tue Jun 03, 2008 3:24 pm
by Oren
Why the heck you are echo-ing $out?? you should be writing it to a file.

Re: setting headers & printing content issue

Posted: Tue Jun 03, 2008 6:43 pm
by lefnire
well i tried that, writing to a file then doing readfile(); but that didn't make a difference. should it make a difference?