2025年02月11日 建站教程
php没有直接删除非空目录的函数,那么如何利用php语法删除非空目录呢?下面web建站小编给大家详细介绍一下具体实现代码!
php删除非空目录写法:
<?php
header("Content-type: text/html; charset=utf-8");
$dir='mydir';
function deldir($dir){
if(file_exists($dir)){
$files=scandir($dir);
foreach($files as $file){
if($file!='.' && $file!='..'){
$path=$dir.'/'.$file;
if(is_dir($path)){
deldir($path);
}else{
unlink($path);
}
}
}
rmdir($dir);
return true;
}else{
return false;
}
}
if(deldir($dir)){
echo "目录删除成功!";
}else{
echo "没有目录!";
}
本文链接:http://so.lmcjl.com/news/22933/