Skip to content

Instantly share code, notes, and snippets.

@waqashassan98
Created July 16, 2018 19:11
Show Gist options
  • Save waqashassan98/6909609880070b41ddfe7cb3e00ca925 to your computer and use it in GitHub Desktop.
Save waqashassan98/6909609880070b41ddfe7cb3e00ca925 to your computer and use it in GitHub Desktop.
Simple Code to dynamically download data from array as csv
$data_to_download = array(
array("Title", "Description", "Comments"),
array("Dummy Title", "Dummy Description", "Dummy Comment Count"),
array("Dummy Title 2", "Dummy Description 2", "Dummy Comment Count 2")
);
$output = fopen("php://output",'w') or die("Can't open php://output");
header("Content-Type:application/csv");
header("Content-Disposition:attachment;filename=".$range.".csv");
foreach($data_to_download as $row) {
fputcsv($output, $row);
}
fclose($output) or die("Can't close php://output");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment