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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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