Last active
February 19, 2020 20:29
-
-
Save doxt3r/5a3a09941b7703129c1d823c6a091246 to your computer and use it in GitHub Desktop.
csvfromArrayOfArrays
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
$tableoftables = []; | |
$response = new StreamedResponse(); | |
$response->setCallback(function() use($tableoftables){ | |
$outputBuffer = fopen("php://output", 'w+'); | |
fputs($outputBuffer, $bom =( chr(0xEF) . chr(0xBB) . chr(0xBF))); | |
foreach($tableoftables as $v) { | |
fputcsv($outputBuffer, $v,';'); | |
} | |
fclose($outputBuffer); | |
}); | |
$dispositionHeader = $response->headers->makeDisposition( | |
ResponseHeaderBag::DISPOSITION_ATTACHMENT, | |
$csvName | |
); | |
$response->headers->set('Content-Type', 'text/csv; charset=ISO-8859-15'); | |
$response->headers->set('Content-Disposition', $dispositionHeader); | |
return $response; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment