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
  • 6,571
  • 9
  • 39
  • 60

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,641
  • 1
  • 19
  • 37
3
header("Content-Disposition", "attachment;filename=myfilename.csv");
dusan
  • 8,824
  • 3
  • 34
  • 54
Andrej Bestuzhev
  • 664
  • 6
  • 10