Symfony 2.3.16에서 이미지를 Response로 제공하고 싶습니다.
그래서 나는 내 행동에서 이것을하고 있습니다.
$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();
내 질문은 시간 기반 해시 등의 다른 이름으로이 이미지를 어떻게 제공 할 수 있습니까? 서버 측에 저장된 것과 다른 이름으로 제공하고 싶습니다.
Symfony2에는이를위한 도우미가 있습니다. 이것은 문서 에서 가져온 것 입니다.
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
$d = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT, // disposition
'foo.pdf' // filename
);
$response->headers->set('Content-Disposition', $d);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다