Created
July 16, 2018 19:11
-
-
Save waqashassan98/6909609880070b41ddfe7cb3e00ca925 to your computer and use it in GitHub Desktop.
Simple Code to dynamically download data from array as csv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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