dongruo4601 2017-06-21 17:34
浏览 75
已采纳

当文件名具有重音时,Symfony BinaryFileResponse强制文件下载

I am trying to show an image directly in the browser with the help of BinaryFileResponse in a Symfony controller.

On our previous server, this code was working all fine:

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

But since the migration on the new server, when the $filePath contains an accent (àéè, etc), it forces the image to download instead of just showing it.

Both servers have PHP 7.0.10 installed.

Am I missing a config or something? I can't find why it happens.

Any help is gretaly appreciated. Thank you.

  • 写回答

1条回答 默认 最新

  • doudeng1870 2017-06-21 19:59
    关注

    I found my problem.

    Symfony could'nt get the filetype mime in path containing accents. To make it possible, I had to activate PHP extension php_fileinfo in Apache.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 宇视监控服务器无法登录
  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)