How to download a temporary file

后端 未结 4 1361
执念已碎
执念已碎 2021-02-05 05:49

I\'m trying to create a short PHP script that takes a JSON string, converts it to CSV format (using fputcsv), and makes that CSV available as a downloaded .csv file

4条回答
  •  南笙
    南笙 (楼主)
    2021-02-05 06:15

    Note that tmpfile() returns a file handle, but all the functions you have need a file path (i.e a string), not a handle - notably basename, filesize, and readfile. So none of those function calls will work correctly. Also basename won't return a file extension either. Just call it whatever you want, i.e

    'Content-Disposition: attachment; filename=data.csv'
    

    As @Joshua Burns also says, make sure you're passing in an array to fputcsv or use the assoc parameter.

提交回复
热议问题