Posted By

kendsnyder on 05/04/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

manteca


Send Data as CSV File


 / Published in: PHP
 

  1. <?php
  2.  
  3. function sendCsv($data, $filename) {
  4. $fp = fopen('php://output', 'w');
  5. foreach ($data as $r) {
  6. fputcsv($fp, $r);
  7. }
  8. $contents = ob_get_clean();
  9. fclose($fp);
  10. header('Content-type: application/octet-stream');
  11. header("Content-Disposition: attachment; filename=\"$filename\"");
  12. echo $contents;
  13. }

Report this snippet  

You need to login to post a comment.