I did some research and I found this post: How to create a link to download generated documents in symfony2?
I tried the solution, but it show my pdf in the browser, but what I want is that when someone click the link, it directly download the file. Is ther a way to do that with Symfony?
Kévin Duguay
Set up an action. This uses annotation for the route. YOu can of course use yml or xml or whatever you are currently using
/**
* @Route("/download", name="download_file")
**/
public function downloadFileAction(){
$response = new BinaryFileResponse('path/to/pdf.pdf');
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT,'pdf.pdf');
return $response;
}
Twig template:
<a href="{{path('download_file')}}">Download file</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With