Generate a CSV file [solved]

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
kendo451

Generate a CSV file [solved]

Post by kendo451 »

If one wanted to generate a CSV file from CMSMS content module, can you just use a UDT to resend the headers?

Code: Select all

header(‘Expires: 0′);
header(‘Cache-control: private’);
header(‘Cache-Control: must-revalidate, post-check=0, pre-check=0′);
header(‘Content-Description: File Transfer’);
header(‘Content-Type: application/vnd.ms-excel’);
header(‘Content-disposition: attachment; filename=”file_name.xls”‘);
If not, how would one go about generating a CSV file?  Just write it to the uploads folder and then give them a link?
Last edited by kendo451 on Thu Sep 30, 2010 1:55 am, edited 1 time in total.
User avatar
kidcardboard
Forum Members
Forum Members
Posts: 54
Joined: Mon Sep 28, 2009 5:25 pm

Re: Generate a CSV file

Post by kidcardboard »

Something like:

Code: Select all

header("Cache-Control: must-revalidate");
header("Pragma: must-revalidate");
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=filename.csv");
$data="header col1, header col2, header col3\n";
$data .= "row1 col1, row1 col2, row1 col3\n";
.
.
.
print $data;
should work
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Generate a CSV file

Post by calguy1000 »

First you have to clear any output that CMSMS may have already sent.

This is what I do in the Uploads module:

Code: Select all

$handlers = ob_list_handlers(); 
for ($cnt = 0; $cnt < sizeof($handlers); $cnt++) { ob_end_clean(); }
then output your header() lines, etc.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “Developers Discussion”