【发布时间】:2014-10-08 10:41:01
【问题描述】:
我在“app/var/assets”中有一些图像(我必须将这些图像放在那个目录中,我无法通过客户端限制来更改它)。
我需要展示这些图片。 App 目录不是 Apache 的可访问路径,所以我需要使用 X-Send File。
我怎样才能使用 X-Send 文件呢?
我在我的控制器中尝试过:
$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; 文件名=
有什么想法吗?
【问题讨论】:
标签: image symfony x-sendfile