symfony2重定向到流文件

hendra1

嗨,大家好,我在symfony2中有一个小问题。

您能告诉我如何在控制器中重定向以打开(流式传输)资产文件夹中的文件而不强制下载

例如:我在root / web / bundles / ace / file.pdf中有一个文件

我使用了这段代码,但是无法打开/ stream文件。此代码强制浏览器下载

        $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;``

非常感谢您的帮助

亨拉丹

丁乔·托多罗夫(Dincho Todorov)

您应该将Content-Disposition设置为inline

$response->headers->set('Content-Disposition', 'inline;filename="'.$fileName);

PS检查此捆绑包https://github.com/igorw/IgorwFileServeBundle

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章