How to download a temporary file

后端 未结 4 1353
执念已碎
执念已碎 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:11

    One problem is that tmpfile() returns a file handle, while filesize takes a filename as parameter.
    The following line:

    header('Content-Length: ' . filesize($tmp));
    

    probably gets evaluated as:

    header('Content-Length: 0');
    

    Check that all the calls to header() are executed before any output happens.

提交回复
热议问题