@@ -481,17 +481,18 @@ non-ASCII filenames is more involving. The
481
481
:method: `Symfony\\ Component\\ HttpFoundation\\ ResponseHeaderBag::makeDisposition `
482
482
abstracts the hard work behind a simple API::
483
483
484
+ use Symfony\Component\HttpFoundation\Response;
484
485
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
485
486
486
- $d = $response->headers->makeDisposition(
487
+ $fileContent = ...; // the generated file content
488
+ $response = new Response($fileContent);
489
+
490
+ $disposition = $response->headers->makeDisposition(
487
491
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
488
492
'foo.pdf'
489
493
);
490
494
491
- $response->headers->set('Content-Disposition', $d);
492
-
493
- Then you must set the file's content as usual, for example by using
494
- :method: `Symfony\\ Component\\ HttpFoundation\\ Response::setContent `.
495
+ $response->headers->set('Content-Disposition', $disposition);
495
496
496
497
Alternatively, if you are serving a static file, you can use a
497
498
:class: `Symfony\\ Component\\ HttpFoundation\\ BinaryFileResponse `::
@@ -513,6 +514,7 @@ if it should::
513
514
With the ``BinaryFileResponse ``, you can still set the ``Content-Type `` of the sent file,
514
515
or change its ``Content-Disposition ``::
515
516
517
+ // ...
516
518
$response->headers->set('Content-Type', 'text/plain');
517
519
$response->setContentDisposition(
518
520
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
0 commit comments