您的位置:首页 > 编程语言 > PHP开发

php删除文件夹及其下面的文件

2013-01-31 14:07 246 查看
php删除文件:unlink()函数

<?php
echo unlink('test.doc');
?>

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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php 删除文件