* @template-extends Response> */ class DownloadResponse extends Response { /** * Creates a response that prompts the user to download the file * @param string $filename the name that the downloaded file should have * @param C $contentType the mimetype that the downloaded file should have * @param S $status * @param H $headers * @since 7.0.0 */ public function __construct(string $filename, string $contentType, int $status = Http::STATUS_OK, array $headers = []) { parent::__construct($status, $headers); $filename = strtr($filename, ['"' => '\\"', '\\' => '\\\\']); $this->addHeader('Content-Disposition', 'attachment; filename="' . $filename . '"'); $this->addHeader('Content-Type', $contentType); } }