Answers for "symfony how to respond in-memory file"

PHP
0

symfony how to respond in-memory file

// 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;
Posted by: Guest on April-28-2021

Browse Popular Code Answers by Language