My PHP script is generating a CSV file.
Upon clicking the download link, I want the browser to treat it as an attachment and show a download prompt.
This works correctly in Firefox but Internet Explorer 8 just shows the CSV file as text.
This is the PHP code generating the headers:
return new Response( $vOutput, 201, array
(
'Content-Encoding' => 'UTF-8',
'Content-Type' => 'application/octet-stream; charset=UTF-8',
'Content-Transfer-Encoding' => 'binary',
'Content-Disposition' => 'attachement; filename="entrance_stats_line' . $vLine . '.csv"',
'Pragma' => '',
'Cache-Control' => '',
'Content-Length' => strlen( $vOutput ),
'Expires' => '0'
)
);
(The framework used is Silex, relying on Symfony’s Symfony\Component\HttpFoundation\Response class, although I’m not sure that’s relevant )
The HTTP headers as received by Firefox (using Tamper Data) are:
Status=Created - 201
Date=Wed, 30 Jan 2013 15:53:38 GMT
Server=Apache/2.2.21 (Win32) PHP/5.3.10
X-Powered-By=PHP/5.3.10
Content-Encoding=UTF-8
content-transfer-encoding=binary
Content-Disposition=attachement;filename="entrance_stats_line1.csv";
Cache-Control=no-cache
Content-Length=6141
Connection=close
Content-Type=application/octet-stream; charset=UTF-8
I haven’t checked if the headers are modified in IE but I’ll post them if I manage to make Fiddler work.
I had tried a few other combinations of headers previously, including the following:
Status=Created - 201
Date=Wed, 30 Jan 2013 16:34:46 GMT
Server=Apache/2.2.21 (Win32) PHP/5.3.10
X-Powered-By=PHP/5.3.10
Content-Encoding=UTF-8
Content-Disposition=attachement; filename=entrance_stats_line1.csv
Cache-Control=no-cache
Connection=close
Content-Type=text/csv; charset=UTF-8
This just gives me a “Requested site could not be found” error.
The IE version is 8.0.6001.18702
It’s “attachment”, not “attachement”.
(also: there is no Content-Transfer-Encoding header field in HTTP)