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
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.