Example #1
0
 /**
  * 删除指定key的缓存,若$key===true则表示删除全部
  *
  * @param string $key
  */
 public function delete($key)
 {
     if (true === $key) {
         # 删除全部
         return File::remove_dir($this->dir);
     }
     if (is_array($key)) {
         # 支持多取
         $data = array();
         $i = 0;
         foreach ($key as $k => $v) {
             if ($this->delete((string) $v)) {
                 $i++;
             }
         }
         return $i == count($key) ? true : false;
     }
     $filename = $this->get_filename_by_key($key);
     if (!file_exists($filename)) {
         return true;
     }
     return File::unlink($filename);
 }
Example #2
0
 /**
  * 删除指定key的缓存,若$key===true则表示删除全部
  *
  * @param string $key
  */
 public function delete($key)
 {
     if ($this->is_file_write_disalbed) {
         return false;
     }
     if (true === $key) {
         # 删除全部
         return File::remove_dir($this->dir . $this->prefix, $this->storage);
     }
     if (is_array($key)) {
         # 支持多取
         $data = array();
         $i = 0;
         foreach ($key as $k => $v) {
             if ($this->delete((string) $v)) {
                 $i++;
             }
         }
         return $i == count($key) ? true : false;
     }
     $filename = $this->get_filename_by_key($key);
     return File::unlink($filename, $this->storage);
 }
Example #3
0
 /**
  * 转移目录下的所有目录和文件,多服务器可以自动同步,可操作非空目录
  *
  * @param string $fromdir  源文文件目录
  * @param string $todir  目标文件目录
  * @param boolean $autocoverageold 是否覆盖已有文件,true覆盖,false跳过
  * @param string $storage 物理存储组,不传则为默认
  * @return array($dook,$doerror)
  */
 public static function move_dir($fromdir, $todir, $autocoverageold = true, $storage = 'default')
 {
     $fromdir = rtrim($fromdir, '\\/') . DS;
     $todir = rtrim($todir, '\\/') . DS;
     if ($fromdir == $todir) {
         return array(0, 0);
     }
     $info1 = File::check_and_get_path($fromdir);
     $info2 = File::check_and_get_path($todir);
     if (File::can_do_run($storage)) {
         if (!is_dir($fromdir)) {
             return array(0, 0);
         }
         # 完成数
         $donum = array(0, 0);
         if (!is_dir($todir)) {
             # 创建目标目录
             File::create_dir($todir, false, $storage);
         }
         # 列出目录中当前级别的目录和文件
         $files = glob($fromdir . '*');
         foreach ($files as $file) {
             # 目标文件
             $tofile = $todir . basename($file);
             if (is_dir($file)) {
                 # 如果当前是目录,则移动目录
                 # 移动目录
                 $donum2 = File::move_dir($file, $tofile, $autocoverageold, $storage);
                 if ($donum2) {
                     $donum[0] += $donum2[0];
                     $donum[1] += $donum2[1];
                 }
             } else {
                 # 文件
                 if ($autocoverageold && file_exists($tofile)) {
                     //覆盖已有文件
                     @unlink($tofile);
                 }
                 if (@rename($file, $tofile)) {
                     $donum[0]++;
                 } else {
                     $donum[1]++;
                 }
             }
         }
         //移除旧目录
         File::remove_dir($fromdir);
         return $donum;
     } else {
         return File::call_http_host($storage, 'file/move_dir', $info1[0], $info1[1], $info2[0], $info2[1], $autocoverageold);
     }
 }
Example #4
0
 /**
  * 内部调用删除目录
  *
  */
 public function action_remove_dir()
 {
     # 目录
     $dir = $this->arguments[0];
     if (!isset(File::$dir[$dir])) {
         # 目录不允许操作
         $this->show_error('目录不允许操作');
     }
     if (!$this->arguments[1]) {
         $this->show_error('缺少参数');
     }
     # 目录
     $the_dir = File::$dir[$dir] . $this->arguments[1];
     if (File::remove_dir($the_dir)) {
         $this->show_success();
     } else {
         # 记录错误日志
         Core::log('system.error.dir.remove', array('dir' => $the_dir), LOG_ERR);
         $this->show_error('执行失败');
     }
 }
Example #5
0
 /**
  * 内部调用删除目录
  *
  */
 public function action_remove_dir()
 {
     # 目录
     $dir = $this->arguments[0];
     if (!isset(File::$dir[$dir])) {
         # 目录不允许操作
         $this->show_error('目录不允许操作');
     }
     if (!$this->arguments[1]) {
         $this->show_error('缺少参数');
     }
     # 目录
     $the_dir = File::$dir[$dir] . $this->arguments[1];
     if (File::remove_dir($the_dir)) {
         $this->show_success();
     } else {
         # 记录错误日志
         Core::log('remove dir(' . $the_dir . ') error.', 'error');
         $this->show_error('执行失败');
     }
 }
Example #6
0
 /**
  * 内部调用删除目录
  *
  */
 public function action_remove_dir()
 {
     # 目录
     $dir = $this->arguments[0];
     if (!isset(\File::$dir[$dir])) {
         # 目录不允许操作
         static::show_error('目录不允许操作');
     }
     if (!$this->arguments[1]) {
         static::show_error('缺少参数');
     }
     # 目录
     $the_dir = \File::$dir[$dir] . $this->arguments[1];
     if (\File::remove_dir($the_dir)) {
         static::show_message('success', null, 1);
     } else {
         # 记录错误日志
         \Core::log('remove dir(' . $the_dir . ') error.', 'error');
         static::show_error('执行失败');
     }
 }