Browse Source

rmdir support all sub dirs and files

master
wen 2 years ago
parent
commit
f7243a133c
  1. 30
      controller/ApiController.php

30
controller/ApiController.php

@ -215,7 +215,7 @@ Class ApiController extends Controller {
} }
try { try {
$res = rmdir("{$target}/{$delDir}"); $res = $this->deleteDirTree( realpath("{$target}/{$delDir}") );
if ($res) { if ($res) {
$code = 1; $code = 1;
$msg = '目录删除完成'; $msg = '目录删除完成';
@ -397,6 +397,34 @@ Class ApiController extends Controller {
return $this->renderJson(compact('code', 'msg', 'err', 'data')); return $this->renderJson(compact('code', 'msg', 'err', 'data'));
} }
protected function deleteDirTree($parentDir) {
if (empty($parentDir)) {return false;}
$res = true;
try {
$dir = opendir($parentDir);
while(false !== ($file = readdir($dir))) {
if ($file != '.' && $file != '..') {
$subpath = "{$parentDir}/{$file}";
if (is_dir($subpath)) {
$res = $this->deleteDirTree($subpath);
}else {
unlink($subpath);
}
}
}
closedir($dir);
rmdir($parentDir);
}catch(Excepiton $e) {
$res = false;
}
return $res;
}
//从runtime/admin/目录里获取管理员当前ip相关的缓存数据 //从runtime/admin/目录里获取管理员当前ip相关的缓存数据
protected function getAdmUserData() { protected function getAdmUserData() {
$data = array(); $data = array();

Loading…
Cancel
Save