Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function update_json_file($obj) {
- $dir = 'sites/default/files/json_data/';
- $filename = 'static.json';
- if(!is_dir($dir)) mkdir($dir) ;
- $full_path = $dir.$filename;
- $resourse = fopen($full_path,'r');
- $data = fread($resourse, filesize($full_path));
- fclose($resourse);
- $current_data = json_decode($data);
- if (!$current_data) {
- $current_data = new \stdClass();
- }
- foreach ($obj as $key => $value){
- $current_data->$key = $value;
- }
- $resourse = fopen($full_path,'w+');
- fwrite($resourse, json_encode($current_data));
- fclose($resourse);
- }
Add Comment
Please, Sign In to add comment