Question : symfony how to respond in-memory file
Answered by : niki-romagnoli
// Generate response
$response = new Response();
$filename = 'yourFileName.txt';
// Set headers
$response->headers->set('Cache-Control', 'private');
$response->headers->set('Content-type', $yourMimeType );
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '";');
$response->headers->set('Content-length', strlen($yourContentString));
// Send headers before outputting anything
$response->sendHeaders();
// Send content
$response->setContent( $yourContentString );
return $response;
Source : https://stackoverflow.com/questions/41804695/return-an-in-memory-file-in-symfony | Last Update : Wed, 05 May 21