|
Posted by Bent Stigsen on 03/12/06 15:45
Geoff Berrow wrote:
> I'm trying to output the results of a database query as a csv file
>
> The DB output is in $csv
>
> foreach($csv as $array){
> $line[]=implode($delimited_by,$array)."\n";
> }
> header("Content-Type: text/plain");
> header("Content-Disposition: inline");
>
> foreach($line as $output){
> print $output;
>
>
> On clicking the link to this file the results are output to the screen.
> I can right click and save the output but I'm prompted to save it as a
> .php file. How can I make it output as the right kind ( .csv) of file?
There is a rfc stating "text/csv" as the mime-type, but it is quite
recent, so probably not widely recognized.
http://www.rfc-archive.org/getrfc.php?rfc=4180
Presently, I think the common way is to set disposition to attachment
and supply a filename, and let the OS figure out how to open it.
header('Content-Disposition: attachment; filename="foo.csv"');
/Bent
Navigation:
[Reply to this message]
|