From bb9241cb5856f2386c11723ade1d53e3336c1c05 Mon Sep 17 00:00:00 2001 From: Dennis Fridrich Date: Sun, 10 Apr 2016 21:37:38 +0200 Subject: [PATCH 1/5] Added docs for file helper --- book/controller.rst | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/book/controller.rst b/book/controller.rst index c768b33407d..e7a1e74f8ac 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -778,6 +778,31 @@ There are also special classes to make certain kinds of responses easier: :class:`Symfony\\Component\\HttpFoundation\\StreamedResponse`. See :ref:`streaming-response`. +File helper +~~~~~~~~~~~ + +If you want to serve file use +:method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::file` +helper:: + + use Symfony\Component\HttpFoundation\File\File; + use Symfony\Component\HttpFoundation\ResponseHeaderBag; + + // This will send file with original name as attachment to browser + public function fileAction() + { + // Load file from file system + $file = new File('some_file.pdf'); + + return $this->file($file); + } + + // You can send nonexistent files too (this will be sent with inline disposition) + public function helloFileAction() + { + return $this->file('Hello, world!', 'hello.txt', ResponseHeaderBag::DISPOSITION_INLINE, 'text/plain'); + } + .. seealso:: Now that you know the basics you can continue your research on Symfony From 819b3c5427d209f02dadd35f59fc51fb73d65ce6 Mon Sep 17 00:00:00 2001 From: Dennis Fridrich Date: Sun, 10 Apr 2016 22:20:56 +0200 Subject: [PATCH 2/5] Update docs for JSON helper --- book/controller.rst | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/book/controller.rst b/book/controller.rst index e7a1e74f8ac..d4355d883e7 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -785,6 +785,19 @@ If you want to serve file use :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::file` helper:: + $this->file($file, $fileName = null, $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT, $mimeType = null); + +You can pass: + +* Instance of + :class:`Symfony\\Component\\HttpFoundation\\File` + in ``$file`` parameter (you can customize ``$fileName`` and ``$disposition``) + +* String with file content in ``$file`` and appropriate ``$fileName``, ``$disposition`` (or just + ``null`` to use default ``ResponseHeaderBag::DISPOSITION_ATTACHMENT``) and ``$mimeType`` + +Example usage:: + use Symfony\Component\HttpFoundation\File\File; use Symfony\Component\HttpFoundation\ResponseHeaderBag; From 8e60a991e80db53ecd7deb7e01079705d9518b3c Mon Sep 17 00:00:00 2001 From: Dennis Fridrich Date: Mon, 11 Apr 2016 12:17:54 +0200 Subject: [PATCH 3/5] Update docs for file helper --- book/controller.rst | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/book/controller.rst b/book/controller.rst index d4355d883e7..3ccfd2bfe50 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -785,7 +785,7 @@ If you want to serve file use :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::file` helper:: - $this->file($file, $fileName = null, $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT, $mimeType = null); + $this->file($file, $fileName = null, $disposition = ResponseHeaderBag::DISPOSITION_ATTACHMENT); You can pass: @@ -793,8 +793,9 @@ You can pass: :class:`Symfony\\Component\\HttpFoundation\\File` in ``$file`` parameter (you can customize ``$fileName`` and ``$disposition``) -* String with file content in ``$file`` and appropriate ``$fileName``, ``$disposition`` (or just - ``null`` to use default ``ResponseHeaderBag::DISPOSITION_ATTACHMENT``) and ``$mimeType`` +* Path to file in ``$file`` parameter + +* String with file content in ``$file`` and appropriate ``$fileName`` Example usage:: @@ -810,10 +811,16 @@ Example usage:: return $this->file($file); } + // Server file from specified path + public function pathFileAction() + { + return $this->file('/path/to/my/picture.jpg'); + } + // You can send nonexistent files too (this will be sent with inline disposition) public function helloFileAction() { - return $this->file('Hello, world!', 'hello.txt', ResponseHeaderBag::DISPOSITION_INLINE, 'text/plain'); + return $this->file('Hello, world!', 'hello.txt', ResponseHeaderBag::DISPOSITION_INLINE); } .. seealso:: From f9ff7d1ea93d8b3950e1c42c3a2b83bd068bffbb Mon Sep 17 00:00:00 2001 From: Dennis Fridrich Date: Wed, 15 Jun 2016 10:29:24 +0200 Subject: [PATCH 4/5] Remove files from string functionality from file helper --- book/controller.rst | 8 -------- 1 file changed, 8 deletions(-) diff --git a/book/controller.rst b/book/controller.rst index 3ccfd2bfe50..62ec08c94f1 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -795,8 +795,6 @@ You can pass: * Path to file in ``$file`` parameter -* String with file content in ``$file`` and appropriate ``$fileName`` - Example usage:: use Symfony\Component\HttpFoundation\File\File; @@ -817,12 +815,6 @@ Example usage:: return $this->file('/path/to/my/picture.jpg'); } - // You can send nonexistent files too (this will be sent with inline disposition) - public function helloFileAction() - { - return $this->file('Hello, world!', 'hello.txt', ResponseHeaderBag::DISPOSITION_INLINE); - } - .. seealso:: Now that you know the basics you can continue your research on Symfony From 8e7be8a54ebafa7f0216ff06cf4bb8c4a03454c4 Mon Sep 17 00:00:00 2001 From: Dennis Fridrich Date: Mon, 20 Jun 2016 11:05:29 +0200 Subject: [PATCH 5/5] Fix typos --- book/controller.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/book/controller.rst b/book/controller.rst index 62ec08c94f1..d8d02e1212c 100644 --- a/book/controller.rst +++ b/book/controller.rst @@ -781,7 +781,7 @@ There are also special classes to make certain kinds of responses easier: File helper ~~~~~~~~~~~ -If you want to serve file use +If you want to serve file use the :method:`Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller::file` helper:: @@ -789,7 +789,7 @@ helper:: You can pass: -* Instance of +* An instance of :class:`Symfony\\Component\\HttpFoundation\\File` in ``$file`` parameter (you can customize ``$fileName`` and ``$disposition``)