php 删除文件夹,及其其下所有文件
在php中删除文件和删除目录我们都用unlink删除实现删除,如果要删除不是空目录主要利用readdir和opendir来遍历目录了.
实例代码如下:
<?php
// 删除文件夹,及其其下所有文件
function deldir($dir) {
$dh = opendir($dir);
while ($file = readdir($dh)) {
if ($file != "." && $file != "..") {
$fullpath = $dir . "/" . $file;
if (!is_dir($fullpath)) {
unlink($fullpath);
} else {
deldir($fullpath);
}
}
}
closedir($dh);
if (rmdir($dir)) {
return true;
} else {
return false;
}
}
?>本文地址:http://www.phprm.com/develop/fs2556.html
转载随意,但请附上文章地址:-)