1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| /**
* @Route("/tickets/file/{id}", name="acme_front_support_ticket_file_download")
*/
public function ticketFileDownloadAction($id)
{
/* @var $tfile TicketFile */
$ticketFile = $this->getDoctrine()->getRepository('AcmeMainBundle:TicketFile')->find($id);
if (!$ticketFile) {
throw $this->createNotFoundException("TicketFile {$id} not found");
}
/* @var $file File */
$file = new File($ticketFile->getAbsolutePath());
$headers = array(
'Content-Type' => $file->getMimeType(),
'Content-Disposition' => 'attachment; filename="'.$ticketFile->getName().'"',
);
return new Response(file_get_contents($file), 200, $headers);
} |
Partager