Php 显示来自web目录外部的图像
我需要显示存储在项目目录之外的图像。结构如下:Php 显示来自web目录外部的图像,php,symfony,symfony5,Php,Symfony,Symfony5,我需要显示存储在项目目录之外的图像。结构如下: symfony项目 第二个项目/ /src/ /资产/ /图像 提供直接路径不起作用。像这样:,使用{{asset('direct_path')也没有完成任务 我目前正在尝试使用控制器路径来执行此操作,它当前看起来如下所示: /** * @Route("/admin/getphoto/{filename}", name="get_photo") */ publi
- symfony项目
- 第二个项目/
- /src/
- /资产/
- /图像
,使用{{asset('direct_path')
也没有完成任务
我目前正在尝试使用控制器路径来执行此操作,它当前看起来如下所示:
/**
* @Route("/admin/getphoto/{filename}", name="get_photo")
*/
public function getPhoto($filename) {
$path = realpath($this->getParameter('uploads_directory' . '/' . $filename));
return file($path, ['ContentType' => 'image/jpeg']);
}
我的模板如下所示:
/**
* @Route("/admin/getphoto/{filename}", name="get_photo")
*/
public function getPhoto($filename) {
$path = realpath($this->getParameter('uploads_directory' . '/' . $filename));
return file($path, ['ContentType' => 'image/jpeg']);
}
/**
* @Route("/admin/getphoto/{filename}", name="get_photo")
*/
public function getPhoto($filename) {
$file = $this->getParameter('uploads_directory') . '/' . $filename;
$response = new Response();
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $filename);
$response->headers->set('Content-Disposition', $disposition);
$response->headers->set('Content-Type', 'image/png');
$response->setContent(file_get_contents($file));
return $response;
}
与
创造了奇迹,谢谢