我在「app/var/assets」中有一些圖像(我必須將這些圖像放在該目錄中,我無法通過客戶端限制來更改此圖像)。使用X-Send文件顯示圖像(Symfony2)
我需要顯示這些圖像。 App目錄不是Apache的可訪問路徑,所以我需要使用X-Send File。
如何爲此使用X發送文件?
我想在我的控制器:
$path = $this->get('kernel')->getRootDir() . '/var/assets/example.jpg';
$response = new BinaryFileResponse($path');
$response->trustXSendfileTypeHeader();
$response->headers->set('Content-type', 'image/jpg');
$response->sendHeaders();
$response->setContentDisposition(ResponseHeaderBag::DISPOSITION_INLINE, "name");
然後在我的觀點:
<img src="<?= $response ?>" />
但圖像沒有發現和網址我得到的圖像是:
HTTP/1.0 200 OKCache-Control:publicContent-Disposition:inline; filename =
有什麼想法嗎?
謝謝,但是如何在您的視圖中打印此圖像?謝謝! – user2794692 2014-10-08 14:27:02