How to download a temporary file

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

    json_decode() by default translates elements into objects rather than arrays. fputcsv() expects the data passed to be an array.

    I'd recommend changing:

    $jsonArray = json_decode( $_POST['json'] );
    

    To:

    $jsonArray = json_decode( $_POST['json'], True );
    

    And see if that doesn't fix your problem.

    When attempting to tackle problems such as these I'd highly recommend enabling display_errors and setting error_reporting to E_ALL to see if there some sort of error you are missing out on:

提交回复
热议问题