<?php
include(dirname(__FILE__)."/../global.php");


include('../../../include/file_type.php');

@$job = $submitted_vars["job"];

?>
<html>
<head>
<title>Powered by 126cms.com</title>
<meta name='keywords' content='mmcbbs,web126,news,bbs,board,php,mysql,forums'>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.font {
	font-size: 12px;
}
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" class="font">
<?php
    $dir = $submitted_vars['dir'];
    $label = $submitted_vars['label'];
	
if( $job == "uploadfile" ){
	
	$fileArr   = $_FILES['postfile'];
	$file_name = $fileArr['name'];
	$file_type = GetFiletype($file_name);
	$file_size = ceil($fileArr['size']/1024);
	##----      检查文件格式       ---##
	if(!validate_format($file_type)){
	exit("<br /><CENTER>不允许上传该格式文件，允许的图片格式为：gif,jpg,jpeg<br />请再次上传，如果多次失败，请联系管理员<br /><a href=\"javascript:history.go(-1)\"> 点击返回</a></CENTER>");
	}
	##----      检查文件大小是否超过限制       ---##
	if($webdb['upfileMaxSize']){
		if($file_size > $webdb['upfileMaxSize']){
		exit("<br /><CENTER>图片文件太大，上传的图片不能大于".$webdb['upfileMaxSize']."K<br /><a href=\"javascript:history.go(-1)\"> 点击返回</a></CENTER>");
		}
	}
	
	$id  =  date("Ymdhis").'-'.rands('4');//时间加有机字符作为文件名 
	
	$newfile = $dir."/".$id.'.'.$file_type;//upload 目录下面的 目录+文件名

	$fileuplodeurl = "../../../upload/".$newfile;
	
	if(copy( $fileArr['tmp_name'] , $fileuplodeurl )){
	
		$fn="upfile";
		
		echo "上传成功,<A HREF=?fn=$fn&label=$label&dir=$dir&label=$_GET[label]>继续上传</A>";
		
		echo "
			<script>
				if(self==top){
					window.opener.$fn('$newfile','$file_name','$file_size','$label');
					window.self.close();
				}else{
					window.parent.$fn('$newfile','$file_name','$file_size','$label');
				}
			</script>
			";
		exit;

	}else{
	    echo "<CENTER>文件上传失败,请再次上传，如果多次失败，请联系管理员<br /><a href=\"javascript:history.go(-1)\"> 点击返回</a></CENTER>";
		exit;
	}
}


?>
<form name="form1" method="post" action="" enctype="multipart/form-data">
  <input  type="file" name="postfile" style="height:20px; background-color:#EBEBEB; border:1 solid black;" onMouseOver ="this.style.backgroundColor='#F0F0F0'" onMouseOut ="this.style.backgroundColor='#FAFAFA'" >
  <input  type="submit" name="Submit" value="上传文件" style="height:20px; background-color:#EBEBEB; border:1 solid black;" onMouseOver ="this.style.backgroundColor='#F0F0F0'" onMouseOut ="this.style.backgroundColor='#FAFAFA'" >
  <input name="job" type="hidden" id="job" value="uploadfile">
  <input name="dir" type="hidden" id="dir" value="<?=$dir?>">
  <input name="label" type="hidden" id="label" value="<?=$label?>">
</form>
</body>
</html>