i'm using this config.yml.
knp_gaufrette:
adapters:
uploaded_files:
local:
directory: "%kernel.root_dir%/../web/uploads"
create: true
filesystems:
uploaded_files:
adapter: uploaded_files
alias: uploaded_files
Now i want to access uploaded files per twig. Also for example:
<a href="{{ path('gaufrette_download', {system: 'uploaded_files', file: 'test.txt'}) }}>{{ 'Download' | trans }}</a>
The file should have a path like...
http://localhost/web/uploads/test.txt
I want a direct access to the file(s). No controller (action).
Is this possible? Any ideas?
If your folder is web-accessible (i.e. you can type the url http://localhost/web/uploads/test.txt
in your address bar and download the file), all you have to do is map the route gaufrette_download
to that path. Your bundle's routing.yml
could look like this (notice the missing defaults: { controller: ... }
):
gaufrette_download:
path: /web/uploads/{file}
If your .htaccess
is defined properly your web server should serve the file instead of accessing your application. You might have to add requirements for file
, e.g. to allow for slashes (search the symfony cookbook for this)
If you just want to skip writing a controller (action), you could just as well create an event listener which is triggered when your request matches the route.