Loading csv through php



  • When applied to the button, a csv data file should be developed and downloaded.

    There's a function getCsvFile. ♪ ♪ )

    Data are developed and the data file remains on the server. But I need him to get a client through the loading.

    Please tell me you're not.

    Thanks.

    $now = gmdate("D, d M Y H:i:s");
    header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate");
    header("Last-Modified: {$now} GMT");
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
    header("Content-Disposition: attachment;filename=test.csv");
    header("Content-Transfer-Encoding: binary");
    

    //$array = $this->getLinks(...);
    $titles = array("id", "Test");
    ob_start();
    $df = fopen("test.csv", "w");
    fputcsv($df, $titles, ';');

    $data = array(
    array(1,2),
    array(1,2),
    array(1,2),
    array(1,3)
    );

    foreach ($data as $row) {
    fputcsv($df, $row, ';');
    }
    fclose($df);



  • Content-Type should be alone.
    And for csv, you need to point text/csv

    header("Content-type: text/csv");
    

    Example - https://stackoverflow.com/a/6493794/5673266 ♪


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2