📅  最后修改于: 2022-03-11 14:53:44.089000             🧑  作者: Mango
// 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;