Created
October 13, 2015 09:53
-
-
Save rettal/f3d0646a7a4ca5458c28 to your computer and use it in GitHub Desktop.
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
function convert_to_csv($input_array, $output_file_name, $delimiter) | |
{ | |
/** open raw memory as file, no need for temp files, be careful not to run out of memory thought */ | |
$f = fopen('php://memory', 'w'); | |
/** loop through array */ | |
foreach ($input_array as $line) { | |
/** default php csv handler **/ | |
fputcsv($f, $line, $delimiter); | |
} | |
/** rewrind the "file" with the csv lines **/ | |
fseek($f, 0); | |
/** modify header to be downloadable csv file **/ | |
header('Content-Type: application/csv'); | |
header('Content-Disposition: attachement; filename="' . $output_file_name . '";'); | |
/** Send file to browser for download */ | |
fpassthru($f); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment