<?php
/***********************************************************
    [WaiKuCms] (C)2011 - 2012 waikucms.com
    
	@function 编辑器文件管理ajax删除

    @Filename ajax_file_delete.php $

    @Author pengyong $

    @Date 2012-12-25 14:46:44 $
*************************************************************/
error_reporting(0);
session_start();
define('THINK_PATH', true);
$config = include('../../../Config/config.ini.php');
$uname = cookie('uname');
$uid = cookie('uid');
$cmsauth = $_SESSION['cmsauth'];
$nowauth = substr(md5(strrev($uname).'waikucms'.$uid),0,10);
if(strcmp($cmsauth,$nowauth) <> 0)
{
   echo '身份认证信息失败!请重新登陆!';die();
}
$suffix  =array('.php','.htm','.html','.js');
empty($_POST['path']) ? die('0') : $path = $_POST['path'];
foreach($suffix as $v)
{
	if(strtolower(substr($path,-1,strlen($v)))==$v)
	{
		 echo '非法删除操作!';die();
	}
}
	$path = rtrim($_SERVER['DOCUMENT_ROOT'],'/').$path;
	if(is_dir($path))
	{
		if(del_dir($path))
		{
			  echo 1;die();
		}
		 echo '删除文件夹失败!';die();
	}
	else
	{
		if(unlink($path))
		{
			echo 1;die();
		}
		echo '删除文件失败!';die();
	}

	/*
		@function  		删除目录
		
		@var:$dirName  	原目录
			
		@return:   		成功=true
	*/
	
	function del_dir($dirName)
	{
		if (!file_exists($dirName))
		{
			return false;
		}
    
		$dir = opendir($dirName);
		while ($fileName = readdir($dir))
		{
			$file = $dirName . '/' . $fileName;
			if ($fileName != '.' && $fileName != '..') 
			{
				if (is_dir($file))
				{
					del_dir($file);
				} 
				else 
				{
					unlink($file);
				}            
			}
		}
		closedir($dir);
		return rmdir($dirName);			
	}
	
	function cookie($name)
	{
		global $config;
		$prefix = $config['COOKIE_PREFIX'];
		return $_COOKIE[$prefix.$name];
	}