3

I have a string which contains csv data. Can I somehow offer that string for download as a csv file without saving it before?

Thanks

user1856596
  • 7,027
  • 10
  • 41
  • 63

2 Answers2

12
<?php
      header("Content-type: application/octet-stream");
      header("Content-Disposition: attachment; filename=\"my-data.csv\"");
      $data="col1, col start and end col2,col3, \n";
      $data .= "second line data";
      echo $data;
?>

Above code will display a window in visitor browser asking to save file in local computer or open by suitable application.

laxonline
  • 2,657
  • 1
  • 20
  • 37
3
header("Content-Disposition", "attachment;filename=myfilename.csv");
dusan
  • 9,104
  • 3
  • 35
  • 55
Andrej Bestuzhev
  • 674
  • 6
  • 10