Have a problem with files json
its my code and my code php is here:
<?php
$json = $_POST['json'];
/* sanity check */
$file = fopen('../js/json/nameplaylist.json','w+');
fwrite($file, $json);
fclose($file);
?>
I need that when the name is saved, I can not overwrite the entire file sinuses, which I added to the end of the list and then display it in a select
SOLVED:
<?php
$in_array = json_decode($_POST['json'], true);
$file_array = json_decode(file_get_contents('../js/json/nameplaylist.json'), true);
$new_array = array_merge($file_array, $in_array);
file_put_contents('../js/json/nameplaylist.json', json_encode($new_array));
?>