php 递归删除目录

.is_file:判断是否是文件

is_dir:判断是否为目录

file_exists = is_file + is_dir 判断是文件或目录

function delDir($dirPath) {

  $dir = opendir($dirPath);

  while ($file = readdir($dir)) {

    if ($file == '.' || $file == '..') {

      continue ; 

    }

    $filePath = $dirPath.'/'.$file;

    if (is_file($filePath)) {

      unlink($filePath);

    } else {

      delDir($dirPath);

    }

  }

  rmdir($dirPath);

  closedir($dir);

}