I feel like I am missing obvious here, but I will post anyway.
I have a 'csv.php' which creates a csv file, simple example:
// csv.php
$fh = fopen('report.csv', 'w') or die("can't open file");
while ($row = mysql_fetch_row($result)) {
fputcsv($fh, $row);
}
fclose($fh);
On a seperate page, there is a simple anchor element that links to the file above. So on home.html there is:
<a href='report.csv'>Report</a>
One user will run csv.php and another will goto home.html and click the link at a later point in time. This works fine, the CSV is created, the data is there, and the anchor links through.
I know that if I were echoing out the CSV, I would add the various headers such as:
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");
But how do I add these headers to the file report.csv? I assume this is required because firefox refuses to see the csv as a downloadable file (when the anchor is clicked, it just outputs the csv to the browser).
.htaccessfile: css-tricks.com/snippets/htaccess/…mod_cern_metaormod_headersto piggyback those extra headers via.htaccess