How to make fputcsv “echo” the data

后端 未结 4 2020
孤独总比滥情好
孤独总比滥情好 2021-01-01 09:56

I need a way to make the fputscv function write data to the browser on-the-fly instead of creating a temporary file, saving data into that file and doing a echo file_g

4条回答
  •  余生分开走
    2021-01-01 10:35

    As the original asker wanted to "write to the browser on the fly", maybe is worth noting (as was my case and noone mentioned it) that if you want to force a file name and a dialog asking to download a file in the browser, you must set the proper headers before outputting anything with fputcsv:

    header('Content-Type: text/csv; charset=utf-8');
    header('Content-Disposition: attachment; filename=myFile.csv');
    

提交回复
热议问题