How to create a download link in Symfony2?

I am trying to put links in my Symfony2 project where people can upload files by clicking the link. However, the moment the user clicks on the link, I get the following error:

No route found for "GET / uploads / test / test-audio-live.wmv"

How to allow download without this error?

+1
symfony
source share
3 answers

If the file really exists, it should not be processed even by Symfony or PHP. If you get this error, it means that Symfony is looking for a route to serve this URL, so your file does not actually exist in the shared folder. Check your rights.

+4
source share

Be sure to place the file in test-audio-live.wmv in the web/uploads/test folder and make it readable by the apache user.

Also make sure that the apache virtual host (if you are using apache) is configured so that the root directory is web . I assume this is also done using .htaccess, but I'm not sure.

+3
source share

To create a downloadable link, make sure you have the uploads directory or a similar directory in the web / directory of your application. Suppose you have PDF files in the web / pdf / directory with the catalog.pdf file, and you want to create a downloadable link for it in Symfony, you can do this as follows

 <a href="{{ asset('pdf/') }}catalog.pdf" target="_blank">Download PDF</a> 

Assets will directly point to the web folder of your application.

As soon as you click on the link, it will open in a new tab, since I added target = "_ blank"

0
source share

All Articles