📜  symfony 如何响应内存中的文件 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:44.089000             🧑  作者: Mango

代码示例1
// 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;