...

View Full Version : problem exporting data to csv file



NuttyMonk
09-17-2011, 11:42 AM
Hi all,

this is the code i'm using at the moment which is at the bottom of a webpage


// Open file export.csv.
$f = fopen("export.csv", "w");

// Put all values from $out to export.csv.
fputs($f, $out);
fclose($f);

$filename = "StatisticalAnalysis-" . gmdate("Y-m-d-H-i-s") . ".csv";

header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=" . $filename);
readfile("export.csv");

The variable named $out is a long line of text in csv format. I've echoed that variable and the code is all good.

When a checkbox in a form further up the page is checked the code creates and fills in the $out variable and then carries out the code above.

The problem i have is that when the csv save dialog comes up and the file is saved, all it contains is a copy of the html code which is on that page, not the info stored in the $out variable.

Can anyone offer any advice on what the problem is?

Cheers

sunfighter
09-17-2011, 02:44 PM
The question is where did you echo the $out? Just after you set the variable or just before you wrote to the file. You should do both to see if $out is being changed.

M1Creative
09-18-2011, 05:22 AM
Yes, show the code for the bit where you create the content for $out and it might come clear?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum