Page 1 of 1

Generate a CSV file [solved]

Posted: Mon Aug 30, 2010 2:43 pm
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?

Re: Generate a CSV file

Posted: Wed Sep 29, 2010 10:49 pm
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

Re: Generate a CSV file

Posted: Wed Sep 29, 2010 11:03 pm
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.