When I go the /test-csv
route in Safari/Firefox, I am able to download the one-line csv file. But when I try it in Chrome, it says 'Failed to load Response Data' in the Network tab of the console.
*edit*
IMPORTANT NEW DETAIL: It does work in Chrome on a Windows Computer, but not on my Macbook Pro
*edit*
I have tried several variations of the Content-Type
and Content-Disposition
headers to no avail.
When I leave out all headers, I get just a string in the browser: "id,name,email"
(no download).
Do I need some kind of special header for Chrome to let me me force a download of this streamed data?
use Symfony\Component\HttpFoundation\StreamedResponse;
Route::get('test-csv', function(){
$response = new StreamedResponse(function(){
// Open output stream
$handle = fopen('php://output', 'w');
fputcsv($handle, [
'id',
'name',
'email'
]);
fclose($handle);
}, 200, [
'Content-Type' => 'text/csv',
'Content-Disposition' => 'attachment;filename=export.csv;',
]);
return $response;
});