Php symfony2重定向到流文件
嗨,伙计们,我有一个关于symfony2的小问题 您能告诉我如何在控制器中重定向以打开(流)资产文件夹中的文件吗 不强制下载Php symfony2重定向到流文件,php,symfony,redirect,Php,Symfony,Redirect,嗨,伙计们,我有一个关于symfony2的小问题 您能告诉我如何在控制器中重定向以打开(流)资产文件夹中的文件吗 不强制下载 $path = $this->get('kernel')->getRootDir().DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."web".DIRECTORY_SEPARATOR."bundles".DIRECTORY_SEPARATOR. "bsibkpm".DIRECT
$path = $this->get('kernel')->getRootDir().DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."web".DIRECTORY_SEPARATOR."bundles".DIRECTORY_SEPARATOR.
"bsibkpm".DIRECTORY_SEPARATOR."download".DIRECTORY_SEPARATOR . $fileName;
//echo $path;die();
$content = file_get_contents($path);
$response = new Response();
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Content-Disposition', 'attachment;filename="'.$fileName);
$response->sendHeaders();
$response->setContent($content);
return $response;``
例如:
我在root/web/bundles/ace/file.pdf中有一个文件
我使用了此代码,但无法打开/流式传输文件。此代码强制浏览器下载
$path = $this->get('kernel')->getRootDir().DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."web".DIRECTORY_SEPARATOR."bundles".DIRECTORY_SEPARATOR.
"bsibkpm".DIRECTORY_SEPARATOR."download".DIRECTORY_SEPARATOR . $fileName;
//echo $path;die();
$content = file_get_contents($path);
$response = new Response();
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Content-Disposition', 'attachment;filename="'.$fileName);
$response->sendHeaders();
$response->setContent($content);
return $response;``
非常感谢你以前的帮助
Hendrawan您应该将内容配置设置为内联
$response->headers->set('Content-Disposition', 'inline;filename="'.$fileName);
请检查这个包裹