Skip to content

Commit b08a595

Browse files
committed
minor #19518 [HttpFoundation] Add support for \SplTempFileObject in BinaryFileResponse (alexandre-daubois)
This PR was merged into the 7.1 branch. Discussion ---------- [HttpFoundation] Add support for `\SplTempFileObject` in `BinaryFileResponse` Fix #19513 Commits ------- 0e03673 [HttpFoundation] Add support for `\SplTempFileObject` in `BinaryFileResponse`
2 parents 6c4eceb + 0e03673 commit b08a595

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

components/http_foundation.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,23 @@ It is possible to delete the file after the response is sent with the
841841
:method:`Symfony\\Component\\HttpFoundation\\BinaryFileResponse::deleteFileAfterSend` method.
842842
Please note that this will not work when the ``X-Sendfile`` header is set.
843843

844+
Alternatively, ``BinaryFileResponse`` supports instances of ``\SplTempFileObject``.
845+
This is useful when you want to serve a file that has been created in memory
846+
and that will be automatically deleted after the response is sent::
847+
848+
use Symfony\Component\HttpFoundation\BinaryFileResponse;
849+
850+
$file = new \SplTempFileObject();
851+
$file->fwrite('Hello World');
852+
$file->rewind();
853+
854+
$response = new BinaryFileResponse($file);
855+
856+
.. versionadded:: 7.1
857+
858+
The support for ``\SplTempFileObject`` in ``BinaryFileResponse``
859+
was introduced in Symfony 7.1.
860+
844861
If the size of the served file is unknown (e.g. because it's being generated on the fly,
845862
or because a PHP stream filter is registered on it, etc.), you can pass a ``Stream``
846863
instance to ``BinaryFileResponse``. This will disable ``Range`` and ``Content-Length``

0 commit comments

Comments
 (0)