PHP删除文件(夹)

来源:互联网 发布:大连淘宝开店学校 编辑:程序博客网 时间:2024/04/29 01:39

删除文件夹

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;  }}

删除文件夹下的所有文件

function recursiveDelete($str){        if(is_file($str)){            return @unlink($str);        }        elseif(is_dir($str)){            $scan = glob(rtrim($str,'/').'/*');            foreach($scan as $index=>$path){                recursiveDelete($path);            }            return @rmdir($str);        }    }


0 0
原创粉丝点击