-
-
//Read file content - $fh = fopen($path, "r+");
if( flock($ fh, lock_ex) ){//Add write lock
- $old_content=json_decode(fread($fh,filesize($path)),true);
$old_content=$old_content.$new_content ;
- ftruncate($fh,0); // Truncate the file to the given length
- rewind($fh); // Rewind the position of the file pointer
- fwrite($fh,json_encode($old_content));
- / / @chmod($path,0644);
- flock($fh, lock_un); //Unlock
}
- fclose($fh);
-
Copy Code
|