File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -841,6 +841,23 @@ It is possible to delete the file after the response is sent with the
841
841
:method: `Symfony\\ Component\\ HttpFoundation\\ BinaryFileResponse::deleteFileAfterSend ` method.
842
842
Please note that this will not work when the ``X-Sendfile `` header is set.
843
843
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
+
844
861
If the size of the served file is unknown (e.g. because it's being generated on the fly,
845
862
or because a PHP stream filter is registered on it, etc.), you can pass a ``Stream ``
846
863
instance to ``BinaryFileResponse ``. This will disable ``Range `` and ``Content-Length ``
You can’t perform that action at this time.
0 commit comments