I am trying to allow a user to upload a file and it works fine in Firefox. My problem is that in Chrome it does not seem to accept the file name that I give in the header, it just ignores it and creates something of its own, and I notice that its sending double headers are identical.
HTTP/1.1 200 OK Date: Tue, 11 Feb 2014 16:25:19 GMT Server: Apache/#.#.## (Linux OS) X-Powered-By: PHP/#.#.## Cache-Control: private Pragma: public Content-Description: File Transfer Content-Disposition: attachment; filename="Filename_3_from_2014_02_11_11_25_19_Custom.csv" Content-Transfer-Encoding: binary Content-Length: 9 Cache-Control: private Pragma: public Content-Description: File Transfer Content-Disposition: attachment; filename="Filename_3_from_2014_02_11_11_25_19_Custom.csv" Content-Transfer-Encoding: binary X-ChromePhp-Data: <Stuff here> X-Debug-Token: 2f50fc Connection: close Content-Type: text/plain; charset=UTF-8
A file created from the above is Filename_3_from_2014_02_11_11_25_19_Custom.csv-, attachment , which is different from what the header tells it to receive.
The code sending the headers is below:
// Generate response $response = new Response(); // Set headers $response->headers->set('Pragma', 'public'); $response->headers->set('Cache-Control', 'private', false); $response->headers->set('Content-Type', 'text/plain'); $response->headers->set('Content-Description', 'File Transfer'); $response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"'); $response->headers->set('Content-Type', 'text/plain'); $response->headers->set('Content-Transfer-Encoding', 'binary'); $response->headers->set('Content-Length', strlen($filedata));
Am I missing the title Chrome needs, or do I need to subtly change one of these titles to make it work properly? I tried the application / force -download, application / vnd.ms-excel as my CSV, intended for use in Excel, but none of them work.
I tried things from this question: HTTP headers for uploading files , but nothing worked.
Gyhth
source share