Create a CSV File for a user in PHP

前端 未结 19 2037
故里飘歌
故里飘歌 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:25

    To have it send it as a CSV and have it give the file name, use header():

    http://us2.php.net/header

    header('Content-type: text/csv');
    header('Content-disposition: attachment; filename="myfile.csv"');
    

    As far as making the CSV itself, you would just loop through the result set, formatting the output and sending it, just like you would any other content.

提交回复
热议问题