<?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){
	//echo $filename,$up_dir,$m_type;exit();

	$chk_up_s = false;
	$filename = $_FILES[$filename] ;
	if ($filename['size']<=0)  echo  "<script language=javascript type=text/javascript>alert('您未选择需要上传的图片');history.back();</script> ";
	$file_size_max=2048000;
	$max_size  || $max_size = $file_size_max;
	$chk_size = $filename['size'];
	switch ($m_type){
		case 1:
			$m_type = array('.gif'=>'image/gif','.jpg'=>'image/pjpeg');
			$up_dir = $up_dir.'/images';
			break;
		case 2:
			$m_type = array('.rar'=>'application/rar','.zip'=>'application/zip');
			$up_dir = $up_dir.'/file';
			break;
		case 3:
			$m_type = array('.mp3'=>'audio/mpeg','.rm'=> 'audio/x-pn-realaudio','wav'=> 'audio/x-wav',);
			$up_dir = $up_dir.'/other';
			break;
	}
	$t_type = strrchr(strtolower($filename['name']),'.');
	$chk_size>$max_size && Showmsg('flle_size_err');
	foreach ($m_type as $key=>$v){
		if ($key  == $t_type && $v == $filename['type']) {
			$db_up != 0 ? $file_name = $name.$t_type : $file_name = R_P.$up_dir.'/'.date("Y-m-d",time());
			!file_exists($file_name) &&  (mkdir($file_name)  || Showmsg('mkdir_err'));
			//$upnames=null 条件不为空是。生成的文件名为$upnames的值否则为时间
			$upnames != null ?  $up_dir = $file_name.'/'.$upnames :  $up_dir = $file_name.'/'.time().$t_type;
			//结束
			(move_uploaded_file($filename['tmp_name'],$up_dir) && chmod($up_dir,0777)) or print  "<script language=javascript type=text/javascript>alert('上传 出错了！');history.back();</script>";
			$up_dirs = str_replace(R_P,'',$up_dir);
			$chk_up_s = true;

		}
	}
	if ($chk_up_s) return $up_dirs;
	else print  "<script language=javascript type=text/javascript>alert('非法类型！');history.back();</script>";

}




?>


