<?php 
/*
*多文件上传处理类
* 2014 5 18
*引入此文件即可使用
*/

class file{
	
	public $path;       //上传文件的路径
	public $allowtype; //所允许上传的文件类型(全部小写)
	
	
function __construct($path,$allowtype){
		$this->path      =  $path;
		$this->allowtype =  $allowtype;
		//return $this -> upfile();
	}

public function mkdirpath(){
        $dir = $this->path;
        //文件创建函数 格式 a/b/c;
        $dirarr=explode("/",$dir);
		for($i=0;$i<count($dirarr);$i++){
			$dirpath .= $dirarr[$i].'/';
			if(!is_dir($dirpath)){
				mkdir($dirpath); 
				}
			}
		
		}
public function upfile(){
	$this->mkdirpath();
	foreach($_FILES as $value)
	{
		$D = date('YmdHis');
		$filetype   =  substr(strrchr($value['name'],'.'),1);
		$newname    =  MD5($value['name']).time().'.'.$filetype;
		$UploadFile =  $this->path.'/'.$newname;
		echo root_path.'/'.$UploadFile;
		$error = $value['error'];
		$back[] = 'NULL';
		if(in_array(strtolower($filetype),$this->allowtype))
		{
			if(move_uploaded_file($value['tmp_name'],$UploadFile))
			{
				$back[] = $newname;
			}		
		}
	}
	return $back;
}

/*
	类结束 end
*/
}