我有一个从okhttp3发送多个数据的Android应用程序,但是我找不到记录php中发送的所有数据的方法。我的当前日志只包含最后一条记录(如下所示)。我最好的猜测是,php文件数据被覆盖,直到最后一条记录。如何记录发送的所有数据?是的,所有数据都是从Android应用程序发出的......
的index.php
if (isset($_POST))
{
file_put_contents("post.log",print_r($_POST,true));
}
示例post.log
Array
(
[date] => 02 Aug, 12:22
[company] => Assert Ventures
[lattitude] => 32.8937542
[longitude] => -108.336584
[user_id] => Malboro
[photo_id] => 1
)
我想要什么
(
[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
)
答案 0 :(得分:3)
您需要传递第三个参数FILE_APPEND
;
所以你的PHP代码看起来像这样,
if (isset($_POST))
{
file_put_contents("post.log",print_r($_POST,true),FILE_APPEND);
}
FILE_APPEND 标志有助于将内容附加到结尾 文件而不是覆盖内容。
答案 1 :(得分:1)
我认为你应该添加FILE_APPEND标志。
<?php
$file = 'post.log';
// Add data to the file
$addData = print_r($_POST,true);
// Write the contents to the file,
// using the FILE_APPEND flag to append the content to the end of the file
// and the LOCK_EX flag to prevent anyone else writing to the file at the same time
file_put_contents($file, $addData, FILE_APPEND | LOCK_EX);
?>