<?php
class clear{
	static function isEmpty($path){ //判断目录是否为空
		$handle = opendir($path);
		$i = 0;
		while(false !== ($file = readdir($handle))){
			$i++;
		}
		closedir($handle);
		if($i >= 2){
			return false;
		}else{
			return true;
		}
	}

	static function deleteDir($dirnm){
		$d = dir($dirnm);
		while(false !== ($entry = $d->read())){
			if($entry == '.' || $entry == '..' || stripos($entry, '.lock')){
				continue;
			}
			$currele = $d->path.'/'.$entry;
			
			if(is_dir($currele)){
				if(clear::isEmpty($currele)){
					if(!rmdir($currele)){
						continue;
					}
				}else{
					clear::deleteDir($currele);
				}
			}else{
				if(!unlink($currele)){
					continue;
				}
			}
		}
		$d->close();
		//rmdir($dirnm);//删除该目录
		return true;
	}
}
?>