doutang3077 2016-08-09 13:22
浏览 49
已采纳

如何使用file_put_contents()将数据附加到文件?

I have an android app that sends multiple data from okhttp3 but i can't find a way to log all the data sent in php..My current log only houses the last record(Show below). My best guess is that the php file data is being overwritten until the last record..How can I log all the data sent? And yes all the data is being sent out from the android app...

index.php

if (isset($_POST))
 {
file_put_contents("post.log",print_r($_POST,true));
}

Sample post.log

 Array
(
    [date] =>  02 Aug, 12:22
    [company] => Assert Ventures
    [lattitude] => 32.8937542
    [longitude] => -108.336584
    [user_id] => Malboro
    [photo_id] => 1
)

What I want

(
   [date] =>  02 Aug, 12:22
   [company] => Three Ventures
   [lattitude] => 302.8937542
   [longitude] => -55.336584
   [user_id] => Malboro
   [photo_id] => 1
),
(
   [date] =>  02 Aug, 12:22
   [company] => Two Ventures
   [lattitude] => 153.8937542
   [longitude] => -88.336584
   [user_id] => Malboro
   [photo_id] => 1
),
(
    [date] =>  02 Aug, 12:22
    [company] => Assert Ventures
    [lattitude] => 32.8937542
    [longitude] => -108.336584
    [user_id] => Malboro
    [photo_id] => 1
)
  • 写回答

2条回答 默认 最新

  • douzhi1937 2016-08-09 13:25
    关注

    You need to pass third parameter FILE_APPEND;

    So your PHP code will look something like this,

    if (isset($_POST))
     {
    file_put_contents("post.log",print_r($_POST,true),FILE_APPEND);
    }
    

    FILE_APPEND flag helps to append the content to the end of the file instead of overriding the content.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题