Forum Laravel StreamDownload not forcing download in browser
Working on a simple script to take some data from an odbc connection and then converting it to a csv. I wrote the following
public function Export($data) { $headers = array( "Content-type" => "text/csv", "Content-Disposition" => "attachment; filename=summary.csv", "Pragma" => "no-cache", "Cache-Control" => "must-revalidate, post-check=0, pre-check=0", "Expires" => "0" ); $columns = array('Period', 'Revenue Area', 'Subs'); $callback = function() use ($data, $columns) { $file = fopen('php://output', 'w'); fputcsv($file, $columns); foreach($data as $items) { fputcsv($file, array($items->PERIOD, $items->REVENUE_AREA, $items->SUBS)); } fclose($file); }; return response()->streamDownload($callback, 'prefix-' . date('d-m-Y-H:i:s').'.csv', $headers); }
The data is there, I can dump it. There are no errors , but the browser is just not forcing the download. Any help or suggestions would be greatly appreciated.
Please sign in or create an account to participate in this conversation.
There's no shortage of content at Laracasts. In fact, you could watch nonstop for days upon days, and still not see everything!
Get Started
StreamDownload not forcing download in browser
Working on a simple script to take some data from an odbc connection and then converting it to a csv. I wrote the following
The data is there, I can dump it. There are no errors , but the browser is just not forcing the download. Any help or suggestions would be greatly appreciated.