<?php 
require_once('session.php');
require_once('../fun/funsql.php'); 
require_once('../fun/funlogic.php');
$fp=openfile('../cache/config.txt');
$fps=explode(",,",$fp);
$size=2097152;
?>
<html>
<head>
<title><?php echo $fps[0] ?> - 图片上传</title>
</head>
<script>
function win(){

   window.opener.document.all.imgs.innerText=document.getElementById("imgs").value;
   //window.opener.document.all.bb.innerText=document.getElementById("sex").value;

   window.close();
}
</script>
<body>
<?php 
$file=@$_FILES["file"];
if ($file['name']!=""){
  $type=explode("/",$file['type']);
  if (strtolower($type[0])=='image' and $file['size']<=$size){
    $file_arr=explode(".",$file['name']);
	$arri=count($file_arr)-1;
	$filenames=date("YmdHis").'.'.strtolower($file_arr[$arri]);
	createdir('../upfile/'.strtolower($type[0]));
	$updatedir='../upfile/'.strtolower($type[0]).'/'.$filenames;
	
	copy($file['tmp_name'],$updatedir);
	
	echo "<a href='#' onclick=\"win()\">点击此处直接获取图片地址</a><br />";
	echo "图片地址:<input type=\"hidden\" id=\"imgs\" value=\"".$fps[1]."/upfile/".strtolower($type[0]).'/'.$filenames."\" /> ".$fps[1]."/upfile/".strtolower($type[0]).'/'.$filenames."<br />";
	echo "图片预览:<img src=\"".$fps[1]."/upfile/".strtolower($type[0]).'/'.$filenames."\"><br />";
  }
  else{
    echo tanshow("文件格式不对或大小已超出","");
  }
  
}
else{
  echo "规则不正确";
}
?>

<?php mysql_close();?>