Skip to content

Instantly share code, notes, and snippets.

@steve-todorov
Forked from jackreichert/exportcsv.php
Last active August 29, 2015 14:19
Show Gist options
  • Save steve-todorov/7173b960952dc5f67331 to your computer and use it in GitHub Desktop.
Save steve-todorov/7173b960952dc5f67331 to your computer and use it in GitHub Desktop.
$filename="export.csv";
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$filename");
header("Pragma: no-cache");
header("Expires: 0");
$csv = fopen('php://output', 'w');
foreach($rows as $ind=>$row){
if($ind==0)
fputcsv($csv,array_keys($row));
fputcsv($csv,$row);
}
fclose($csv);
exit();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment