头像

Thinkphp利用代码删除目录

来源:http://school.sxbd100.com/jlhelp/34.html 2018-03-17浏览(69)  评论0

码示例:

//第一个参数是需要删除的路径,

//第二个参数是 是否删除该目录还是删除目录下边的文件,false是不删除,true是删除

function delDirAndFile($path, $delDir = true) { 
if (is_array($path)) { 
foreach ($path as $subPath) 
delDirAndFile($subPath, $delDir); 
} 
if (is_dir($path)) { 
$handle = opendir($path); 
if ($handle) { 
while (false !== ( $item = readdir($handle) )) { 
if ($item != "." && $item != "..") 
is_dir("$path/$item") ? delDirAndFile("$path/$item", $delDir) : unlink("$path/$item"); 
} 
closedir($handle); 
if ($delDir) 
return rmdir($path); 
} 
} else { 
if (file_exists($path)) { 
return unlink($path); 
} else { 
return FALSE; 
} 
} 
clearstatcache(); 
}


调用方式:

$this->delDirAndFile("./uploads/user/");


标签:
声明:本文为原创文章,如需转载,请注明来源daimasucai.com并保留原文链接:http://school.sxbd100.com/jlhelp/34.html

评论(0)


温馨提示:为规范评论内容,垃圾评论一律封号...

后面还有条评论,点击查看>>