Home  >  Article  >  php教程  >  php删除目录几种方法

php删除目录几种方法

WBOY
WBOYOriginal
2016-06-13 11:18:08996browse

php删除目录几种方法本文章提供三款关于php删除目录几种方法,如果你正在找删除目录或删除目录下所有文件的php代码就进来看看吧。  

php教程删除目录几种方法
本文章提供三款关于php删除目录几种方法,如果你正在找删除目录或删除目录下所有文件的php代码就进来看看吧。

deletedir($dir)
{
if (rmdir($dir)==false && is_dir($dir)) {
    if ($dp = opendir($dir)) {
     while (($file=readdir($dp)) != false) {
      if (is_dir($file) && $file!='.' && $file!='..') {
       deletedir($file);
      } else {
       unlink($file);
      }
     }
     closedir($dp);
    } else {
     exit('www.aimeige.com.cn not permission');
    }
}
}

删除目录利用rmdir来删除吧

//比如当前文件所在文件夹下游www.bkjia.com/一个文件夹
@$flag = rmdir("www.bkjia.com/");
if($flag)
{echo "www.zhutiai.com删除成功";}
else
{echo "www.bkjia.com删除失败";}


下面看一款 php删除文件夹及其文件夹下所有文件

function deldir($dir) {
  $dh=opendir($dir);
  while ($file=readdir($dh)) {
    if($file!=”.” && $file!=”..”) {
      $fullpath=$dir.”/”.$file;
      if(!is_dir($fullpath)) {
          unlink($fullpath);//mb.php100.com
      } else {
          deldir($fullpath);
      }
    }
  }

  closedir($dh);
 
  if(rmdir($dir)) {
    return true;
  } else {
    return false;
  }
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php filter_input函数Next article:php 过滤字符串函数