<?php
define('U_ROOT', substr(dirname(__FILE__), 0, -12).'/');
require_once U_ROOT.'include/common.inc.php';
session_start();
if($_SESSION["admin"]!="NewsTeng")die("<script>alert('未登陆不允许上传');window.parent.\$('divProcessing').style.display='none';history.back();</script>");
$act=addslashes($_GET['action']);
$type=addslashes($_GET['uploadtype']);
if($act=='upload'){
	if($type=='attach'){
		$fileType=array('rar','zip');//允许上传的文件类型
	}
	elseif($type=='img'){
		$fileType=array('jpg','gif','bmp','png');
	}
	$upfileDir=UPLOAD_URL;
	$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']> UPLOAD_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=U_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("<script>window.parent.LoadIMG('../{$upfileDir}{$targetFile}');</script>");
	}elseif($type=='attach'){
		die("<script>window.parent.LoadAttach('../{$upfileDir}{$targetFile}');</script>");
	}
}
?>