PHP function to clear multi-level directories

WBOY
Release: 2016-07-25 09:00:29
Original
765 people have browsed it
PHP custom function clears the contents of a directory and subdirectories. The code is simple and concise. Friends in need can refer to it.

The complete code is as follows.

<?php
//清空多层目录
function del_dir($dir){
{
if (!$dir) { return ; }
$cacheDir = $dir;
$dh = opendir($cacheDir);
while ( $file = readdir($dh) ) {

if (($file == '.') || ($file == '..')) { continue; }
if (file_exists( $cacheDir .'/'.$file)) {
  if(is_dir( $cacheDir .'/'.$file)){
     del_dir($cacheDir .'/'.$file);
  }elseif (!unlink($cacheDir .'/'. $file)) {
//删除完操作
}
}
}
}
}
?>
Copy after login


Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template