<?
include_once("inc/config.php");
include_once("inc/ftbbsdbclass.php");
include_once("inc/publicfun.php");
include_once("conn.php");
include_once("admin/check_master.php");

$query = "SELECT * FROM {$tablepre}ftbbsmb";
$ftbbsmb=makecache('ftbbsmb.html',$query,$expire);

$url=$ftbbsmb[10];
$upfiletype="jpg|gif|swf";
$upfilesize=$ftbbsmb[13];
$uploadoff=$ftbbsmb[15];
$waterimg=$ftbbsmb[36];
$uploadvalue=$ftbbsmb[60];
$username=get_cookie('username');
$clubuser_id=get_cookie('clubuser_id');
$now=date("Y-m-d H:i:s");
$filename=$_GET["filename"];
?>
<html><title>保存上传(飞天论坛)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language=javascript src="inc/cookies.js"></script>
<script>
var stylecook = getCookie("STYLESHOW");
var style;
var strstyle;
if(stylecook=="")
{
 stylecook=1;
}
else
{
 stylecook++;
}
style="main0"+stylecook+".css";
strstyle="<link href=\"css/"+style+"\"  rel=\"stylesheet\" type=\"text/css\"> ";
document.write(strstyle);
</script>
<body topmargin="0">
<?
include_once("inc/upload_fun.php");
//按时间创建文件夹
if ($ftbbsmb[7]=="M"){
 $inFolder=date("Ym",time());
 }
else{
 $inFolder=date("Ymd",time());
}
if(!file_exists ($inFolder)){
  mkdir($inFolder,0777);   
}

if(isset($_FILES) && !empty($_FILES['userfile']) && $_FILES['userfile']['size']>0) 
{ 
	$filetype=$_FILES['userfile']['type'];
	$size=$_FILES['userfile']['size'];
	$strFileName=$_FILES['userfile']['name'];
    $arrName  = explode(".",$strFileName);
    $intName = sizeof($arrName);
    $extName = strtolower($arrName[$intName-1]);
	if ($filetype=="text/plain"){
	echo "您上传的文件有问题!&nbsp;&nbsp;<a href=AmFtbbsUpFile.php>重新上传</a>";
	exit;
	}
    if (!in_array($extName,explode("|", $upfiletype))){
	echo "不允许上传".$extName."类型的文件&nbsp;&nbsp;<a href=AmFtbbsUpFile.php>重新上传</a>";
	exit;
    }
    //$uploadfile = $inFolder."/".time()."_".$strFileName;
	$uploadfile = "flashad/".time().".".$extName;
    if(@copy($_FILES['userfile']['tmp_name'], $uploadfile) || (function_exists('move_uploaded_file') && @move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))) 
    { 
		//图片相关信息写入数据库
		//$inFolder/$filename 080412改成$filename
		@unlink($_FILES['userfile']['tmp_name']);
		$insql = "insert into {$tablepre}ftbbs_upload (upload_pic,indate,upload_size,upload_ext,userid,upload_htm,clubuser_id) values('$uploadfile','$now','$size','$extName','$username','$filename','$clubuser_id')";
        mysql_query($insql);
		$id = mysql_insert_id();
		echo "上传成功&nbsp;&nbsp;<a href=AmFtbbsUpFile.php>继续上传</a>";
		ReturnPostFile($extName,$uploadfile);
		//}
    } 
    else 
    { 
        echo "<font color=red>上传文件不能为空</font>&nbsp;&nbsp;<a href=AmFtbbsUpFile.php>重新上传</a>"; 
    } 
}

Function ReturnPostFile($FileExt,$FilePath){
  If ($FileExt=="jpg" || $FileExt=="gif" || $FileExt=="swf"){
?>
<script>
document.ftbbsmenu = new Function('return false')
parent.form1.adtitle.value='<?=$FilePath?>'
</script>
<?
  }
}
?>
</body> 
</html>