Create a CSV File for a user in PHP

前端 未结 19 2113
故里飘歌
故里飘歌 2020-11-22 11:52

I have data in a MySQL database. I am sending the user a URL to get their data out as a CSV file.

I have the e-mailing of the link, MySQL query, etc. covered.

<
19条回答
  •  攒了一身酷
    2020-11-22 12:12

    Create your file then return a reference to it with the correct header to trigger the Save As - edit the following as needed. Put your CSV data into $csvdata.

    $fname = 'myCSV.csv';
    $fp = fopen($fname,'wb');
    fwrite($fp,$csvdata);
    fclose($fp);
    
    header('Content-type: application/csv');
    header("Content-Disposition: inline; filename=".$fname);
    readfile($fname);
    

提交回复
热议问题