HTTP Headers for Chrome

会有一股神秘感。 提交于 2019-12-06 16:29:12

After much playing around with this issue, it turns out that the problem was due to me sending the headers early, and then also returning my response object. Due to this, the headers were being sent twice, which Firefox appears to be perfectly content with, but Chrome becomes very confused and changes the file name to indicate an issue has arisen, but still properly allows the user to download the file.

Basically, I had to remove the line that said $response->sendHeaders(); and simply return the object, thus resolving the issue with double headers, and the file name not formatting properly.

Try

<?php

use Symfony\Component\HttpFoundation\Response;

//...

$file = '/path/of/your/file';

return new Response(file_get_contents($file), 200, array(
    'Content-Disposition' => 'inline; filename="'.$file.'"'
));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!