Reputation: 4558
I am trying to make a link to download a file with symfony2. It does download a file, but it's useless as it is zero octect. I don't know how to make it work. Does anybody know how to do?
The file is in web/uploads/documents/
.
Here is the code in the controller:
// here I get the name of the file
$response = new Response();
$response->headers->set('Content-type', 'application/octet-stream');
$response->headers->set('Content-Disposition', sprintf('attachment; filename="%s"', $filename));
return $response;
I tried to write the whole path instead of $filename
but it changes all the slashes in underscore.
Upvotes: 3
Views: 3425
Reputation: 36191
You forgot to set the content:
$response->setContent(file_get_contents($localFilePath));
Upvotes: 4