Recording a JSON POST to File Using PHP

前端 未结 3 409
遥遥无期
遥遥无期 2020-12-11 09:13

I\'m trying to record data that is being posted to my server to a text file. An example of the data that is being sent to my server is located here:

http://dev.data

3条回答
  •  粉色の甜心
    2020-12-11 09:14

    You are trying to save an object, using file_put_contents. While data parameter this function "Can be either a string, an array or a stream resource"

    http://php.net/manual/en/function.file-put-contents.php

    Look at this example:

    
    

    It parses json correctly, but doesn't save anything as well, because php doesn't know, how to serialize $phpObj object.

    You need to save raw JSON string:

    
    

    Then you can read the file and parse it if necessary.

提交回复
热议问题