Hi there,
I'm developing a block and it works fine on both my testing and production servers. However there is an issue with one part of the code. I am downloading an associated array as a CSV file.
Works fine on the testing server but not on the hosted production server. On the production server I get screen output.
Two questions:
Is there any issue with my code? As I say works on the testing server so think it's OK:
if(isset($associated_array['0'])){
ob_clean();
$fp = fopen('php://output', 'w');
if (!$fp) { die("unable to open file for output"); }
fputcsv($fp, array_keys($associated_array['0']));
foreach($associated_array AS $values){
fputcsv($fp, $values);
}
$string=ob_get_clean();
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;filename="export.csv"');
fclose($fp);
ob_flush();
exit($string);
}
The second question is are there any CSV based library functions in Moodle to do this and therefore guarantee it works.
Cheers
Dave Emsley