Symfony2 forcing jpg download returns corrupted file
问题 Following some of the many posts related to the subject I finally came up with this version of the "force download" code: public function downloadAction(Request $request){ $filename= 'test.jpg'; $response = new Response(); $response->headers->set('Content-Type','image/jpg'); $response->headers->set('Content-Disposition', 'attachment; filename="' . basename($filename) . '"'); $response->sendHeaders(); $response->setContent(file_get_contents($filename)); return $response; } Now, this works fine