/** * 删除目录或者文件 * @param string $path * @param boolean $is_del_dir * @return fixed */ function del_dir_or_file($path, $is_del_dir = FALSE) { $handle = opendir($path); if ($handle) { // $path为目录路径 while (false !== ($item = readdir($handle))) { // 除去..目录和.目录 if ($item != '.' && $item != '..') { if (is_dir("{$path}/{$item}")) { // 递归删除目录 del_dir_or_file("{$path}/{$item}", $is_del_dir); } else { // 删除文件 unlink("{$path}/{$item}"); } } } closedir($handle); if ($is_del_dir) { // 删除目录 return rmdir($path); } } else { if (file_exists($path)) { return unlink($path); } else { return false; } } }
/** * 删除缓存 * @return */ public function delete() { if (empty($_POST['caches'])) { return $this->errorReturn('请选择需要删除的缓存文件!'); } foreach ($_POST['caches'] as $cache) { if (isset($cache)) { del_dir_or_file($cache); } } return $this->successReturn('成功删除缓存文件!'); }
public function removefile($name) { del_dir_or_file(decode($name)); }
public function removefile($name) { del_dir_or_file('.' . $this->ROOT_PATH . decode($name)); }
/** * 删除sql文件 * @return */ public function deleteZipFiles() { if (!IS_POST) { $this->errorReturn('无效的操作!'); } if (!isset($_POST['zip_files'])) { $this->errorReturn('请选择需要删除的zip文件!'); } $backupConfig = C('BACKUP'); foreach ($_POST['zip_files'] as $file) { del_dir_or_file($backupConfig['BACKUP_ZIP_DIR_PATH'] . $file); } $this->successReturn('已删除:' . implode("、", $_POST['zip_files']), U('Data/zipList', array('time' => time()))); }
/** * 过滤安装 * @return */ public function filterInstall() { // 不存在初始化的超级管理员则认为未安装 $installFile = WEB_ROOT . 'install.php'; $host = C('DB_HOST'); if (empty($host) || !D('Admin', 'Service')->existInitAdmin()) { if (!file_exists($installFile)) { echo "缺少<b>{$installFile}</b>文件!"; exit; } // 重定向到安装页 $url = "http://{$_SERVER['HTTP_HOST']}" . __ROOT__ . '/install.php'; echo "<script>location.href='{$url}';</script>"; exit; } $installDir = WEB_ROOT . 'Install'; if (is_dir($installDir) && file_exists($installFile)) { // 删除安装目录 del_dir_or_file($installDir, true); // 删除安装文件 del_dir_or_file($installFile); } }
/** * 写出菜单配置 * @param array $menu 菜单数组 * @return mixed */ public function writeMenu(array $menu) { // 删除缓存 del_dir_or_file(RUNTIME_PATH . '~runtime.php'); return fast_cache('model_menu', $menu, APP_PATH . '/Common/Conf/'); }