I try to upload a file when the user clicks the download link.
In the controller:
$response = new Response(); $response->headers->set('Content-type', 'application/octect-stream'); $response->headers->set('Content-Disposition', sprintf('attachment; filename="%s"', $filename)); $response->headers->set('Content-Length', filesize($filename)); return $response;
This opens a dialog box for saving the file, but it says that the file has 0 bytes. And changing it to:
$response = new Response(); $response->headers->set('Content-type', 'application/octect-stream'); $response->headers->set('Content-Disposition', sprintf('attachment; filename="%s"', $filename)); $response->headers->set('Content-Length', filesize($filename)); $response->headers->set('Content-Transfer-Encoding', 'binary'); $response->setContent(readfile($filename)); return $response;
I get a bunch of weird characters instead of a file download dialog.
Finally, switching the string "setContent" to:
$response->setContent(file_get_contents($filename));
It returns a PHP error:
Fatal error: allowable memory size ...
Any clues on how to achieve this? I did this before in PHP (with MVC), but I donβt know what is missing to do this through Symfony2 ...
Maybe the solution sets memory_limit in PHP.INI, but I think this is not the best practice ...
php header symfony download
Xavi Oct 22 '12 at 11:23 2012-10-22 11:23
source share