|How to use the CSV MIME-type?||#1|
In a web application I am working on, the user can click on a link to a CSV file. There is no header set for the mime-type, so the browser just renders it as text. I would like for this file to be sent as a .csv file, so the user can directly open it with calc, excel, gnumeric, etc.
echo "cell 1, cell 2";
This code works as expected on my computer (Isn't that how it always is?) but does not work on another computer.
My browser is a nightly build of FF 3.0.1 (on linux). The browsers it did not work in were IE 7 and FF 3.0 (on windows)
Are there any quirks I am unaware of?
posted date: 2008-12-29 10:08:00
|Re: How to use the CSV MIME-type?||#3|
You could try to force the browser to open a "Save As..." dialog by doing something like:
header('Content-type: text/csv');header('Content-disposition: attachment;filename=MyVerySpecial.csv');echo "cell 1, cell 2";
Which should work across most major browsers.
posted date: 2008-12-29 10:11:00
|Re: How to use the CSV MIME-type?||#4|
You are not specifying a language or framework, but the following header is used for file downloads:
"Content-Disposition: attachment; filename=abc.csv"
posted date: 2008-12-29 10:14:00
|Re: How to use the CSV MIME-type?||#5|
With Internet Explorer you often have to specify the Pragma: public header as well for the download to function properly..
Just my 2 cents..
posted date: 2011-05-04 01:51:00
|Re: How to use the CSV MIME-type?||#6|
This code can be used to export any file, including csv
// application/octet-stream tells the browser not to try to interpret the fileheader('Content-type: application/octet-stream');header('Content-Length: ' . filesize($data));header('Content-Disposition: attachment; filename="export.csv"');
posted date: 2013-03-08 02:27:00
|Re: How to use the CSV MIME-type?||#7|
"octetstream" is meant to be "octet-stream"
posted date: 2013-08-12 11:38:00
|Re: How to use the CSV MIME-type?||#8|
This can cause a warning in some browsers: Resource interpreted as Document but transferred with MIME type application/octet-stream
posted date: 2013-09-11 09:23:00
|Re: How to use the CSV MIME-type?||#9|
Possibly the actual utility of this is to replace a preexisting Pragma: no-cache header?
posted date: 2014-01-15 06:38:00
|select page: « 1 »|