Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
9eb3b9b2
Commit
9eb3b9b2
authored
Feb 07, 2013
by
Victor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Doc] Document Application::sendFile()
parent
570df9d4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
0 deletions
+31
-0
doc/changelog.rst
doc/changelog.rst
+2
-0
doc/usage.rst
doc/usage.rst
+29
-0
No files found.
doc/changelog.rst
View file @
9eb3b9b2
Changelog
=========
* **2013-02-07**: added ``Application::sendFile()`` to ease sending
``BinaryFileResponse``.
* **2012-11-05**: Filters have been renamed to application middlewares in the
documentation.
...
...
doc/usage.rst
View file @
9eb3b9b2
...
...
@@ -611,6 +611,35 @@ after every chunk::
fclose($fh);
};
Sending a file
--------------
If you want to return a file, you can use the ``sendFile`` helper method.
It eases returning files that would otherwise not be publicly available. Simply
pass it your file path, status code, headers and the content disposition and it
will create a ``BinaryFileResponse`` based response for you::
$app->get('/files/{path}', function ($path) use ($app) {
if (!file_exists('/base/path/' . $path)) {
$app->abort(404);
}
return $app->sendFile('/base/path/' . $path);
});
To further customize the response before returning it, check the API doc for
`Symfony\Component\HttpFoundation\BinaryFileResponse
<http://api.symfony.com/master/Symfony/Component/HttpFoundation/BinaryFileResponse.html>`_::
return $app
->sendFile('/base/path/' . $path)
->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT, 'pic.jpg')
;
.. note::
Http Foundation 2.2 or greater is required for this feature to be available.
Traits
------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment