php 删除目录(删除目录下所有文件)

       /**
	 * 清空目录下所有文件
	 */
	function delStatic($static = '') {
		
		if(empty($static) || $static == '') {
			$static = g('static');
			$dir = $GLOBALS['cms_save_path']. '/' .$static;
		}
		else {
			$dir = $static;
		}
		echo $dir;
		if(is_dir($dir)){
			$dh = opendir($dir);
			
			while ($file = readdir($dh))
			{
				if ($file != "." && $file != "..")
				{
					$fullpath = $dir . "/" . $file;
					if (!is_dir($fullpath))
					{
						unlink($fullpath);
					}
					else {
						echo '<br />';
						$this->delStatic($fullpath);
					}
				}
			}
			
			closedir($dh);
			if (rmdir($dir))
			{
				echo "删除成功<br />";
			} else
			{
				exit("删除成功");
			}
		}
		else {
			exit("没找到文件");
		}
		
	}


你可能感兴趣的:(PHP)