Jump to content

problem exporting data to csv file


NuttyMonk

Recommended Posts

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 it's 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

Link to comment
https://forums.phpfreaks.com/topic/247335-problem-exporting-data-to-csv-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.