Skip to content

Instantly share code, notes, and snippets.

@jackreichert
Created May 24, 2013 16:29
Show Gist options
  • Save jackreichert/5644718 to your computer and use it in GitHub Desktop.
Save jackreichert/5644718 to your computer and use it in GitHub Desktop.
write csv with fputcsv() directly to php://output
$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