Last active
February 22, 2016 15:12
-
-
Save vijinho/38d24d04c39d28a40b18 to your computer and use it in GitHub Desktop.
Convert an array to a csv file
This file contains hidden or 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
<?php | |
$filename = 'report_period_' . date('Y-m-d', $time) . '.csv'; | |
$file = sys_get_temp_dir() . '/' . $filename; | |
$fp = fopen($file, 'w'); | |
foreach ($csvData as $r) { | |
fputcsv($fp, $r); | |
} | |
fclose($fp); | |
$size_in_bytes = filesize($file); | |
$ContentType = 'Content-type: application/vnd.ms-excel'; | |
$ContentLength = "Content-Length: $size_in_bytes"; | |
$ContentDisposition = "Content-Disposition: attachment; filename=\"$filename\""; | |
header($ContentType); | |
header($ContentLength); | |
header($ContentDisposition); | |
readfile($file); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment