Php 服务器发送一个映像作为响应,并在服务之前重命名它-Symfony 2
我想在Symfony 2.3.16中提供一个图像作为响应 所以我在我的行动中这样做:Php 服务器发送一个映像作为响应,并在服务之前重命名它-Symfony 2,php,symfony,http-headers,symfony-2.3,Php,Symfony,Http Headers,Symfony 2.3,我想在Symfony 2.3.16中提供一个图像作为响应 所以我在我的行动中这样做: $image = $this->getDoctrine()->getRepository('MakoBackendBundle:Image')->find($id); if($image !== null) { /** @var $image Image *
$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为此提供了一个帮助程序。这是从
Symfony2为此提供了一个帮助程序。这是从
Symfony2为此提供了一个帮助程序。这是从
Symfony2为此提供了一个帮助程序。这是从
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
$d = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_ATTACHMENT, // disposition
'foo.pdf' // filename
);
$response->headers->set('Content-Disposition', $d);