【问题标题】:Symfony BinaryFileResponse forces file download when filename has an accentSymfony BinaryFileResponse 当文件名有重音时强制文件下载
【发布时间】:2017-06-21 17:34:33
【问题描述】:

我正在尝试借助 Symfony 控制器中的 BinaryFileResponse 在浏览器中直接显示图像。

在我们之前的服务器上,这段代码运行良好:

 $response = new BinaryFileResponse($filePath, 200, [], true, null, true);
 $response->headers->addCacheControlDirective('no-cache', true);
 $response->headers->addCacheControlDirective('max-age', 0);
 $response->headers->addCacheControlDirective('must-revalidate', true);
 $response->headers->addCacheControlDirective('no-store', true);

 return $response;

但自从在新服务器上迁移后,当 $filePath 包含重音符号(àéè 等)时,它会强制下载图像而不是仅仅显示它。

两台服务器都安装了 PHP 7.0.10。

我是否缺少配置或其他内容?我找不到它发生的原因。

非常感谢任何帮助。谢谢。

【问题讨论】:

    标签: php symfony symfony-2.8


    【解决方案1】:

    我发现了我的问题。

    Symfony 无法在包含重音符号的路径中获取文件类型 mime。为此,我必须在 Apache 中激活 PHP 扩展 php_fileinfo。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-03
      • 1970-01-01
      • 1970-01-01
      • 2015-10-02
      相关资源
      最近更新 更多