<?php
/*
$webdb[www_url]/do/upimg1.php?dir=图片目录&thisobjs=父窗口显示位置&upname=按钮名称
父窗口代码
$showpicurl=$rsdb[picurl]?tempdir($rsdb[picurl]):"$webdb[www_url]/images/defalut/nopic.jpg";
<div class="UpImg_qunzucode">
	<div><iframe frameborder=0 height=25 width=100 scrolling=no src='$webdb[www_url]/do/upimg1.php?dir=upimg0/$lfjuid&thisobjs=picurl&upname=上传二维码'></iframe></div>
	<div class="ShowImg"><img src="$showpicurl"/><input type="hidden" name="postdb[picurl]" value="$rsdb[picurl]"/></div>
</div>
<script type="text/javascript">
function upimg1(imgurl,objs,upname){
	$('.UpImg_'+objs+' .ShowImg').html('<img src="{$webdb[www_url]}/{$webdb[updir]}/'+imgurl+'"/><input type="hidden" name="postdb['+objs+']" value="'+imgurl+'"/>');
	$('.UpImg_'+objs+' iframe').attr('src','$webdb[www_url]/do/upimg1.php?dir=upimg0/$lfjuid&thisobjs='+objs+'&upname='+upname+'&'+Math.random());
}
</script>
*/
require_once (dirname(__FILE__).'/global.php');
if(!$lfjid){
	echo '<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
		 <body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0">';
	die("<A HREF='$webdb[www_url]/do/login.php' target='_blank'  onclick='window.self.close();'>请先在前台登录</A>");
}
$thisobjs||$thisobjs="picurl";
$upname||$upname="上传图片";
if($postfile){
	//其中..与/开头都是不允许的
	if( !ereg("^[0-9a-z_/]+$",$dir)||ereg("^/",$dir) ){
		$dir="upimg0/$lfjuid";
	}
	$array[name]=is_array($postfile)?$_FILES[postfile][name]:$postfile_name;
	$array[path]=$webdb[updir]."/".$dir;
	$array[size]=is_array($postfile)?$_FILES[postfile][size]:$postfile_size;
	$array[updateTable]=1;	//统计用户上传的文件占用空间大小
	$filename=upfile(is_array($postfile)?$_FILES[postfile][tmp_name]:$postfile,$array);
	$newfile="$dir/$filename";
	echo "<script>
				window.parent.upimg1(\"$newfile\",\"$thisobjs\",\"$upname\");
		 </script>";
	exit;
}
print <<<EOT
<html>
<head>
<title>请选择图片</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script type="text/javascript" src="$webdb[www_url]/images/default/hf/jquery-v1.7.2.js"></script>
<style type="text/css">
body,h1,h2,h3,h4,h5,h6,hr,p,blockquote,dl,dt,dd,ul,ol,li,pre,form,fieldset,legend,button,input,textarea,th,td{margin:0;padding:0;}
body,button,input,select,textarea{font:12px 'Microsoft Yahei','Simsun';color:#333;}
h1,h2,h3,h4,h5,h6{font-size:100%;}
address,cite,dfn,em,var{font-style:normal;}
code,kbd,pre,samp{font-family:courier new,courier,monospace;}
small{font-size:12px;}
ul,ol{list-style:none;}
a{text-decoration:none;color:#2d374b;}
a:hover {color:#d00;}
sup{vertical-align:text-top;}
sub{vertical-align:text-bottom;}
legend{color:#000;}
fieldset,img{border:0;}
button,input,select,textarea{font-size:100%;}
table{border-collapse:collapse;border-spacing:0;}
img {vertical-align:middle;}
.upbutter{float:left;position:relative;}
.upbutter:after{content:'';display:block;clear:both;}
.upbutter span{display:block;float:left;background:#15C8B1;font-size:14px;line-height:25px;padding:0 8px;color:#FFF;border-radius:3px;}
.upbutter input{ position:absolute; width:100%; height:100%; left:0; top:0; cursor:pointer;filter:alpha(opacity=0);-moz-opacity:0;opacity:0;}
.upbutter:hover span{background:#F60;}
</style>
<SCRIPT LANGUAGE='JavaScript'>
<!--
function selectFileImage(){
	$('form').submit();
}
//-->
</SCRIPT>
</head>
<body>
<form name="form1" method="post" action="" enctype="multipart/form-data">
  <div class="upbutter"><span>$upname</span><input type="file" name="postfile" onChange="selectFileImage();"></div>
  <!--input type="file" id="file" multiple /-->
</form>
</body>
</html>
EOT;
?>