Skip to content

Commit 4fe59bb

Browse files
committed
[#6613] Add fileContent in the example and removed sentence
1 parent 16bf6db commit 4fe59bb

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

components/http_foundation/introduction.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -481,17 +481,18 @@ non-ASCII filenames is more involving. The
481481
:method:`Symfony\\Component\\HttpFoundation\\ResponseHeaderBag::makeDisposition`
482482
abstracts the hard work behind a simple API::
483483

484+
use Symfony\Component\HttpFoundation\Response;
484485
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
485486

486-
$d = $response->headers->makeDisposition(
487+
$fileContent = ...; // the generated file content
488+
$response = new Response($fileContent);
489+
490+
$disposition = $response->headers->makeDisposition(
487491
ResponseHeaderBag::DISPOSITION_ATTACHMENT,
488492
'foo.pdf'
489493
);
490494

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);
495496

496497
Alternatively, if you are serving a static file, you can use a
497498
:class:`Symfony\\Component\\HttpFoundation\\BinaryFileResponse`::
@@ -513,6 +514,7 @@ if it should::
513514
With the ``BinaryFileResponse``, you can still set the ``Content-Type`` of the sent file,
514515
or change its ``Content-Disposition``::
515516

517+
// ...
516518
$response->headers->set('Content-Type', 'text/plain');
517519
$response->setContentDisposition(
518520
ResponseHeaderBag::DISPOSITION_ATTACHMENT,

0 commit comments

Comments
 (0)