<?php
deleteDir('123/');//删除123目录
function deleteDir($dirPath) {
if(!is_dir($dirPath)){
$file_del=[];
$file_del['code']=404;
$file_del['msg']="目录《".$dirPath."》不存在!无需删除!";
$json=json_encode($file_del,JSON_UNESCAPED_UNICODE);
print_r($json);
return;
}
if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
$dirPath .= '/';
}
$files = glob($dirPath . '*', GLOB_MARK);
foreach ($files as $file) {
if (is_dir($file)) {
deleteDir($file);
} else {
unlink($file);
}
}
rmdir($dirPath);
$file_del=[];
$file_del['code']=200;
$file_del['msg']="目录《".$dirPath."》删除成功";
$json=json_encode($file_del,JSON_UNESCAPED_UNICODE);
print_r($json);
return;
}
?>
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
请登录后发表评论
注册
社交帐号登录