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 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应