I want to serve a image as Response in Symfony 2.3.16
So I'm doing this in my action:
$image = $this->getDoctrine()->getRepository('MakoBackendBundle:Image')->find($id);
if($image !== null) {
/** @var $image Image */
$info = getimagesize($image->getAbsolutePath());
$content = file_get_contents($image->getAbsolutePath());
return new Response($content, 200, array(
'Content-Type' => $info['mime'],
'Content-Length' => strlen($content),
'Content-Disposition' => 'attachment;'
));
}
return new Response();
My question is how can I serve this image with a different name, like a time based hash or something? I want to serve it with a different name than it is stored on the server-side.