Export CVS file

Public

Get raw version
php
  1. // send response headers to the browser
  2. drupal_add_http_header('Content-Type', 'text/csv');
  3. drupal_add_http_header('Content-Disposition', 'attachment;filename=csvfile.csv');
  4.  
  5. $csv_array = array(
  6. array('one', 'two', 'three'),
  7. array('1', '2', '3'),
  8. );
  9.  
  10. $fp = fopen('php://output', 'w');
  11. foreach($csv_array as $line){
  12. fputcsv($fp, $line);
  13. }
  14. fclose($fp);
  15. drupal_exit();