setting headers & printing content issue
Posted: Tue Jun 03, 2008 3:14 pm
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:
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
<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;