Just adding the file path to the href attribute didn't work for me.
When a button is clicked, it simply displays the file without downloading it.
Which worked for me, but adds the download attribute to my link, which is an HTML5 attribute. Just add the attribute like this:
<a href="path/to/file" download>Download Link</a>
When you click on the link, it will simply download the file without code on the server side.
You can also assign a value to the download attribute.
<a href="path/to/file" download="filename.txt">Download Link</a>
The value of the download attribute will be used as the file name of the downloaded file, and not the one used when it was stored on the server.
I followed a tutorial on the Symfony website regarding file upload processing. It was useful to me when I figured out how to create a link to download a file. I just added a method to the Document object called getDownloadFileName() , which simply returns the name of the file that I want to assign to the download attribute.
So basically this is how I implemented it on my symfony project twig template
<a href="{{ asset(file.webPath) }}" download="{{ file.downloadFileName }}"> Download Link </a>
schizoskmrkxx
source share