Guest User

Untitled

a guest
Nov 22nd, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. function update_json_file($obj) {
  2. $dir = 'sites/default/files/json_data/';
  3. $filename = 'static.json';
  4. if(!is_dir($dir)) mkdir($dir) ;
  5. $full_path = $dir.$filename;
  6. $resourse = fopen($full_path,'r');
  7. $data = fread($resourse, filesize($full_path));
  8. fclose($resourse);
  9. $current_data = json_decode($data);
  10. if (!$current_data) {
  11. $current_data = new \stdClass();
  12. }
  13. foreach ($obj as $key => $value){
  14. $current_data->$key = $value;
  15. }
  16. $resourse = fopen($full_path,'w+');
  17. fwrite($resourse, json_encode($current_data));
  18. fclose($resourse);
  19. }
Add Comment
Please, Sign In to add comment