json.php 902 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. class ModelJson
  3. {
  4. // json 文件存放路径
  5. public $staticPath = "/home/wwwroot/crazy_god_CMS/public/game/config/";
  6. public function __construct(){
  7. }
  8. public function SaveJson($fileType, $data){
  9. $filename = $fileType . time() . '.json';
  10. $dir = $this->staticPath;
  11. $filepath = "{$dir}{$filename}";
  12. if (!is_dir($dir) || !is_writeable($filepath)) {
  13. // return false;
  14. $old = umask(0);
  15. //mkdir($dir, PRODUCTION_SERVER ? 0775 : 0777, true);
  16. mkdir($dir,0775 , true);
  17. umask($old);
  18. }
  19. $data = json_decode(json_encode($data,JSON_NUMERIC_CHECK), true);
  20. $ret = file_put_contents($filepath, json_encode($data,JSON_UNESCAPED_UNICODE));
  21. if($ret){
  22. oo::commonOprModel("config")->setStaticConfig($fileType, $filename);
  23. }
  24. return $ret;
  25. }
  26. }