本教程操作环境:windows7系统、PHP8.1版、Dell G3电脑。php代码怎么删除非空目录?代码如下:<?php header("Content-type: text/html; charset=utf-8&quo
本教程操作环境:windows7系统、PHP8.1版、Dell G3电脑。
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 "没有目录!";
}
php的非空目录删除,其实是用递归函数实现的,php没有直接删除非空目录的函数。
以上就是php代码怎么删除非空目录的详细内容,更多请关注编程网其它相关文章!
--结束END--
本文标题: php代码怎么删除非空目录
本文链接: https://www.lsjlt.com/news/116968.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0