<?php
if(!defined('IN_TM')) {exit('Access Denied');}
$type=addslashes(getgpc('uploadtype'));
$subname=addslashes(getgpc('subname'));
if (empty($_POST['Submit']))
{
	include template('upload.htm');
	exit;
}
else
{	
	$act=addslashes(getgpc('do'));
	if($act=='upload'){
		if($type=='attach'){
			$fileType=array('rar','7z','tar','z','bz2','gzip','gz','doc','pdf','zip');//允许上传的文件类型
		}
		elseif($type=='img'){
			$fileType=array('jpg','jpeg','gif','bmp','png');
		}
		$upfileDir='uploadfile/';
		$maxSize=2048; //单位：KB
		$fileExt=substr(strrchr($_FILES['file1']['name'],'.'),1);
		if(!in_array(strtolower($fileExt),$fileType))
			die("<script>alert('不允许上传该类型的文件！-808');window.parent.\$('divProcessing').style.display='none';history.back();</script>");
		if($_FILES['file1']['size']> $maxSize*1024)
			die( "<script>alert('文件过大！');window.parent.\$('divProcessing').style.display='none';history.back();</script>");
		if($_FILES['file1']['error'] !=0)
			die("<script>alert('未知错误，文件上传失败！');window.parent.$('divProcessing').style.display='none';history.back();</script>");
		$targetDir=TM_ROOT.$upfileDir;
		$targetFile=date('Ymd').time().strrchr($_FILES['file1']['name'],'.');
		$realFile=$targetDir.$targetFile;
		if(function_exists('move_uploaded_file')){
			 move_uploaded_file($_FILES['file1']['tmp_name'],$realFile);
		}
		else{
			@copy($_FILES['file1']['tmp_name'],$realFile);
		}
		if($type=='img'){
			die( "\r\n\t\t<script>\r\n\t\tparent.document.getElementById('".$subname.( "').value='".$upfileDir.$targetFile."';\r\n\t\t</script>" ));
		}
		elseif($type=='attach')
		{
			die( "\r\n\t\t<script>\r\n\t\tparent.document.getElementById('".$subname.( "').value='".$upfileDir.$targetFile."';\r\n\t\t</script>" ));
		}
	}
}
?>