Chrome会添加“ - ,附件”下载文件 [英] Chrome adds "-, attachment" to downloaded file
问题描述
我使用Symfony2 Framework并使用以下代码导出xml文件:
$ response-> setStatusCode(200 );
$ response-> headers-> set('Content-Type','application / xml');
$ response-> headers-> set('Content-Description','Submissions Export');
$ response-> headers-> set('Content-Disposition','attachment; filename =''。$ filename。'');
$ response-> headers-> set('Content-Transfer-Encoding','binary');
$ response-> headers-> set('Pragma','no-cache');
$ response-> headers-> set('Expires','0');
无论我采用Content-Transfer-Encoding还是Pragma或全部除了Content-Type和Content-Disposition以外。在Chrome中的结果总是:文件名 - ,附件(不带)。
在Firefox中,这项工作正常。
我知道这是一个很老的讨论,但是如果有人在这里寻求帮助,我确定chrome似乎想在文件名末尾加上一个分号,然后它很开心。如(VBScript)所示:
Response.AddHeaderContent-Disposition,attachment; filename = Something.xls;
为我修好了。
-Dave
I use Symfony2 Framework and use the following code to export an xml file:
$response->setStatusCode(200);
$response->headers->set('Content-Type', 'application/xml');
$response->headers->set('Content-Description', 'Submissions Export');
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename .'"');
$response->headers->set('Content-Transfer-Encoding', 'binary');
$response->headers->set('Pragma', 'no-cache');
$response->headers->set('Expires', '0');
I does not matter whether I take "Content-Transfer-Encoding" or "Pragma" or all of them except "Content-Type" and "Content-Disposition" away. The result in Chrome is always: "filename-, attachment" (without the "). In Firefox this works fine.
So for instance, if I have a file called home.xml Firefox will download home.xml, whereas Chrome will give me home.xml-, attachment.
I know this is a pretty old discussion, but if anyone gets here looking for help with this, I determined that chrome seems to want a semicolon at the end of the filename and then it's happy. As in (VBScript):
Response.AddHeader "Content-Disposition", "attachment;filename=Something.xls;"
That fixed it for me. -Dave
这篇关于Chrome会添加“ - ,附件”下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!