I have the following php script.
<?php
create_time_stamp('time_stamp_file.txt');
function create_time_stamp($fname)
{
$fh = fopen($fname, 'c+');
if (!$fh) {
die ('Could not open date stamp file');
}
$time = time();
$time_array = array(
'epochtime' => $time,
'date' => date('Y-m-d H:i:s', $time)
);
fwrite($fh, json_encode($time_array)."\r\n");
}
time_stamp_file.txt had the follwoing in it:
{"epochtime":1482524298,"date":"2016-12-23 20:18:18"}
When I ran the script, I was expdecting to see the following in it:
{"epochtime":1482524540,"date":"2016-12-23 20:22:20"}
{"epochtime":1482524298,"date":"2016-12-23 20:18:18"}
Instead, it only had a single line:
{"epochtime":1482524540,"date":"2016-12-23 20:22:20"}
I thought that c+ means, place the pointer at the beginning of the file, do not truncate it, and open it for read/write. Any ideas?
NOTE: Yes, I can read the file into a buffer, add the data to the beginning, and write it back out to the file, but my question was about the use the c+ flag.