php 创建和删除文件夹

来源:互联网 发布:加内特历年数据 编辑:程序博客网 时间:2024/04/28 08:38

//创建文件夹的方法

//$path 为文件夹参数,如 (c:/program files/makedir)

 

 

 function createFolders($path) {
    if (!file_exists($path)) {
      $this->createFolders(dirname($path));
      mkdir($path, 0777);
    }
  }

 

/////////////////////////

删除文件夹的方法(文件夹里有文件和没有文件都能删除)

 

  function deldir($dir) {
    $dh=opendir($dir);
    while ($file=readdir($dh)) {
      if($file!="." && $file!="..") {
        $fullpath=$dir."/".$file;
        if(!is_dir($fullpath)) {
          unlink($fullpath);
        } else {
          $this->deldir($fullpath);
        }
      }
    }
    closedir($dh);
    if(rmdir($dir)) {
      return true;
    } else {
      return false;
    }
  }