<?php
/*
表单上传多个文件，在file里添加multiple属性，可以一次选择多个文件
$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";
if($postfile){
	//其中..与/开头都是不允许的
	if( !ereg("^[0-9a-z_/]+$",$dir)||ereg("^/",$dir) ){
		$dir="upimg0/$lfjuid";
	}
	$newfile="";
	$i=0;
	foreach($_FILES[postfile][name] AS $key=>$value){
		if($value){			
			$array[name]=$value;
			$array[path]=$webdb[updir]."/".$dir;
			$array[size]=$_FILES[postfile][size][$key];
			$filename=upfile($_FILES[postfile][tmp_name][$key],$array);
			if($filename){
				$i++;
				if($i==1){
				$newfile.="{$dir}/{$filename}";
				}else{
					$newfile.=",{$dir}/{$filename}";
				}
			}			
		}
	}
	echo "<script>
				window.parent.upimg1(\"$newfile\",\"$thisobjs\");
		 </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/jquery-1.2.6.min.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;width:40px;height:40px;border-radius:5px;border:#DDD solid 1px;position:relative;}
.upbutter span:before,.upbutter span:after{content:'';display:bock;background:#DDD;position:absolute;}
.upbutter span:before{width:30px;height:2px;left:5px;top:19px;}
.upbutter span:after{height:30px;width:2px;top:5px;left:19px}
.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{border:#F30 solid 1px;}
.upbutter:hover span:before,.upbutter:hover span:after{background:#F30;}
</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();" multiple /></div>
</form>
</body>
</html>
EOT;
?>