Upload.class.php 1.08 KB
<?php
class Util_Utils_Upload
{
	/**
	 * 判断文件是否是通过 HTTP POST 上传的
	 *
	 * @param string $tmp_name
	 * @return boolean
	 */
	public static function if_uploaded_file($tmp_name) 
	{
		if (!$tmp_name || $tmp_name == 'none') 
		{
			return false;
		} 
		elseif (function_exists('is_uploaded_file') && !@is_uploaded_file($tmp_name) && !@is_uploaded_file(str_replace('\\\\', '\\', $tmp_name))) 
		{
			return false;
		} 
		else 
		{
			return true;
		}
	} 
	
	/**
	 * 创建目录
	 * 
	 * @param string $path
	 */
	public static function createFolder($path) 
	{
		if (!is_dir($path))
		{
			upload::createFolder(dirname($path));
			@mkdir($path);
			@chmod($path,0777);
			@fclose(@fopen($path.'/index.html','w'));
			@chmod($path.'/index.html',0777);
		}
	}
	
	/**
	 * 上传文件
	 * 
	 * @param string $resourceFile
	 * @param string $destinationFile
	 * @return boolean
	 */
	public static function uploadFile($resourceFile, $destinationFile)
	{
		if (@copy($resourceFile, $destinationFile)) 
		{
			@unlink($resourceFile);
			return true;
		}
		else
		{
			return false;
		}
	}
}
?>