dongruo4601 2017-06-21 09: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 11: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部