php 刪除文件夾及文件夾內文件函數


/** delDir()刪除文件夾及文件夾內文件函數
* @param string $path 文件夾路徑
* @param string $delDir 是否刪除改
* @return boolean
*/
function delDir($path, $del = false){
$handle = opendir($path);
if ($handle) {
while (false !== ($item = readdir($handle))) {
if (($item != ".") && ($item != "..")) {
is_dir("$path/$item") ? delDir("$path/$item", $del) : unlink("$path/$item");
}
}

closedir($handle);

if ($del) {
return rmdir($path);
}
}elseif (file_exists($path)) {
return unlink($path);
}else {
return false;
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM