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

class file{
	
	var $path;      //上传文件的路径
	var $username;  //上传文件的用户名
	var $wapid;     //网站的ID
	var $allowtype; //所允许上传的文件类型
	var $nums;      //同时上传的文件个数
	
	
function __construct($wapid,$username,$path,$allowtype,$nums){
		$this->path      =  $path;
		$this->wapid     =  $wapid;
		$this->username  =  $username;
		$this->nums      =  $nums;
		$this->allowtype =  $allowtype;
	
	}

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); 
				}
			}
		
		}
function uploadfile(){		
        //先创建目录
		$this->mkdirpath();
		for($i=1;$i<=$this->nums;$i++){	
		$D = date(YmdHis);
		$filetype   =  substr(strrchr($_FILES['userfile'.$i]['name'],'.'),1);
		$newname    =  $this->username.'_'.$i.'_'.time().'_'.$_FILES['userfile'.$i]['name'];
		$uploaddir  =  $this->path.'/';
		$UploadFile =  $uploaddir.$newname;
		$error = $_FILES['userfile'.$i]['error'];
		if(in_array($filetype,$this->allowtype)){
			if($i==1){
				$fh='';
					}else{
				$fh='|';
					}
			if(move_uploaded_file($_FILES['userfile'.$i]['tmp_name'],$UploadFile)){
				$back .= $fh.$UploadFile;
					}else{
					$back .= $fh.$error;
						}	
					}else{
					$back .= $fh.'6';
					}	
				}
				return $back;
			}		  	
      

    //FUN END 函数结束
	  }
?>