Download as CSV – PHP


For downloading csv files using php.

<?php

  header("Pragma: public");
  header("Expires: 0");
  header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  header("Cache-Control: private",false);
  header("Content-Type: application/csv");
  header("Content-Disposition: attachment; filename=\"output.csv\";" );

 readfile("path to output.csv");
 

?>