コード例 #1
0
 public function write($path, $data, $mode)
 {
     import('ORG.Net.FileSystem');
     $paths = new FileSystem();
     $paths->root = ITEM;
     $paths->charset = C('CFG_CHARSET');
     //main
     if ($mode == 'conf') {
         if (!is_writeable(ROOT . '/Conf')) {
             return -1;
         }
         $fp = fopen($path, 'wb');
         flock($fp, 3);
         fwrite($fp, "<" . "?php\r\n");
         fwrite($fp, "return array(\r\n");
         //dump($data);
         foreach ($data as $fval) {
             $fval['vals'] = htmlspecialchars_decode($fval['vals']);
             if ($fval['types'] == 'int' || $fval['types'] == 'bool') {
                 if ($fval['vals'] == "") {
                     $fval['vals'] = 0;
                 }
                 fwrite($fp, "\t'" . $fval['keyword'] . "' => " . addslashes($fval['vals']) . ",\r\n");
             } elseif ($fval['types'] == 'select' || $fval['types'] == 'more') {
                 list($key, $val) = explode('>>', $fval['vals']);
                 if ($key == 'none') {
                     fwrite($fp, "\t'" . $fval['keyword'] . "' => '',\r\n");
                 } else {
                     fwrite($fp, "\t'" . $fval['keyword'] . "' => '" . addslashes($key) . "',\r\n");
                 }
             } else {
                 fwrite($fp, "\t'" . $fval['keyword'] . "' => '" . addslashes($fval['vals']) . "',\r\n");
             }
         }
         fwrite($fp, ");");
         fclose($fp);
         return 1;
     } elseif ($mode && $mode != 'conf') {
         if (!file_exists($path)) {
             $paths->putDir($path);
         }
         if (!is_writeable($path)) {
             return -1;
         }
         $put = $paths->putFile($path . '/' . $mode . '.json', $data);
         return $put;
     } else {
         $this->error('未知操作模式,请检查!');
     }
 }
コード例 #2
0
 /**
  * 打包下载备份包
  *@param $file    文件路劲
  *@examlpe 
  */
 public function downzip($file)
 {
     import('ORG.Util.phpzip');
     $addzip = new phpzip();
     import('ORG.Net.FileSystem');
     $path = new FileSystem();
     $path->root = ITEM;
     $path->charset = C('CFG_CHARSET');
     load("@.download");
     //main
     $file = strval($file);
     $realpath = CONF_PATH . 'Backup/' . $file;
     $bakfile = RUNTIME_PATH . 'Temp/Zip/';
     if (!file_exists($bakfile)) {
         $path->putDir($bakfile);
     }
     $zipname = 'Backup_' . $file . '.zip';
     $zippath = $bakfile . $zipname;
     $addzip->zip($realpath, $zippath);
     if (file_exists($zippath)) {
         download($zippath);
         $path->delFile($zippath);
     }
     unset($addzip, $path);
 }