lundi 6 août 2018

Laravel stream return string instead of file

I'm trying to download a file created in stream to not have to write it in the disk. Here is what I do :

$response = new StreamedResponse(function() use ($csv_data) {
  // Open output stream
  $handle = fopen('php://output', 'w');
  foreach ($csv_data as $row) {
    fputcsv($handle, $row);
  }
  fclose($handle);

}, 200, [
  'Content-Type' => 'text/csv',
]);


return $response;

I use the StreamedResponse according to the documentation but it's returning me the string of the values of my csvfile ("value1","value2", ...) but not the csvfile itself.

This method is called by an angular app.

What I am doing wrong ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire