se...">

Chrome adds an "- attachment" to the downloaded file

I use the 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'); 

It doesn’t matter if I take "Content-Transfer-Encoding" or "Pragma" or all of them except "Content-Type" and "Content-Disposition". The result in Chrome is always: "filename-, attachment" (without ")". In Firefox, this works great.

So, for example, if I have a file called home.xml, Firefox will load home.xml, while Chrome will provide me with home.xml-, attachment.

+7
google-chrome php symfony content-disposition
Nov 07 '13 at 11:32
source share
2 answers

I know this is a pretty old discussion, but if someone is looking for help with this, I decided that chrome seems to want a comma at the end of the file name, and then it is happy. As in (VBScript):

 Response.AddHeader "Content-Disposition", "attachment;filename=Something.xls;" 

This fixed it for me. -Dave

+3
Mar 23 '15 at 15:48
source share
β€” -

I had the same problem in ZEND because I found a lot of non-working materials that my anwser wanted to add to this post. Since it took me a while to solve the problem, we thought that more users and developers would want to know how I solved it. I add this right before my fopen call.

 header('Content-Disposition: attachment; filename='.time().'.csv'); 

Solved the problem for me. Before I used context, I switched to what was a mistake, but now it works like a charm. Remember to delete previous content headers, so you might get a double header error.

0
Feb 17 '16 at 15:17
source share



All Articles