开发者

output data into CSV file

I'd like to add a link for users to downloa开发者_JS百科d data in .CSV format.

I can format data with PHP, but how do I make the file available to download (click and start downloading) instead of opening it in a browser?


You can force download a file using PHP readfile. You may need to add the appropriate header for your csv (if that's necessary) e.g.

header("Content-Type: text/csv");

Or to make it simple you can do something like:

 header('Content-Disposition: attachment; filename="desired_filename.csv"');
 header("Content-Type: text/csv");
 echo 'your formatted content';

It should bring a download dialog. Hope that helps.


Set the header,

header('Content-Type: application/octet-stream');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜