<?php
//2008.1.9添加$upnames=null 条件不为空是。生成的文件名为$upnames的值 
function up_type($filename,$up_dir,$m_type=1,$db_up=0,$max_size=null,$admin=null,$upnames=null){
	$filename = $_FILES[$filename] ;
	$file_size_max=204800;
	$max_size = $max_size ? $max_size : $file_size_max;
	$m_type == 1 && $m_type = array('.gif'=>'image/gif','.jpg'=>'image/pjpeg');
	$t_type = strrchr($filename['name'] ,'.');
    if($max_size>$file_size_max)
	  {   
	     if($admin==1)
		 echo "<script language=javascript type=text/javascript>alert('您上传的文件大小超过200KB！');history.back();</script>";
		 else
	     Showmsg('flle_size_err');
		 exit;
	    }
	    foreach ($m_type as $key=>$v){
		   if ($key  == strtolower($t_type) && $v == $filename['type'])
		    {
				$db_up==0 ? $file_name = $name.$t_type : $file_name = date("Y-m-d-",time()).time().$t_type;
				//$upnames=null 条件不为空是。生成的文件名为$upnames的值否则为时间 
				$upnames != null ?  $up_dir = R_P.$up_dir.'/'.$upnames :  $up_dir = R_P.$up_dir.'/'.$file_name;
				//结束
				 move_uploaded_file($filename['tmp_name'],$up_dir) or Showmsg('flle_up_err');
				 $up_dirs = str_replace(R_P,'',$up_dir);
				 return $up_dirs;
				 
				 exit;
			}	        	
	    }
			    
		if($admin==1)
	        echo "<script language=javascript type=text/javascript>alert('上传的文件类型出错！');history.back();</script>";
        else 
         Showmsg('flle_type_err');
	     exit;
		
	

}
 
	


?>


