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

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

$url=$ftbbsmb[10];
$upfiletype=$ftbbsmb[12];
$upfilesize=$ftbbsmb[13];
$uploadoff=$ftbbsmb[15];
$waterimg=$ftbbsmb[36];

$userlogin=checkuserlogin();
if ($userlogin=="N"){
   echo "你还没有登录或非法操作,<a href=up_phpoto.php>重新上传</a>";
   exit;
}

//按时间创建文件夹
if ($ftbbsmb[7]=="M"){
 $inFolder=date("Ym",time());
 }
else{
 $inFolder=date("Ymd",time());
}
if(!file_exists ($inFolder)){
  mkdir($inFolder,0777);   
}

$userid=ftbbs_request(get_cookie('clubuser_id'));
$username=ftbbs_request(get_cookie('username'));
$photo_name=ftbbs_request($_POST["photo_name"]);
$photo_note=ftbbs_request($_POST["photo_note"]);
if ($photo_name==""){
   $photo_name="我的相片";
}
$sql="select * from {$tablepre}ftblog_type where userid=".$userid." and blogphoto=1 and blogtype='".$photo_name."'";
$rs=mysql_query($sql);
$myrow = mysql_fetch_array($rs);
$numrows = mysql_num_rows($rs);
if ($numrows!=0){
   $sign=$myrow["sign"];
}

include_once("inc/upload_fun.php");
if(isset($_FILES) && !empty($_FILES['userfile']) && $_FILES['userfile']['size']>0){ 
	if (checkfile($_FILES['userfile']['tmp_name'])==1){
	echo "您上传的文件有问题,<a href=up_photo.php>返回重新上传</a>";
	exit;
	}
	$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 "您上传的文件有问题.";
	  exit;
	}
	if (!in_array($extName,explode('|', $upfiletype))){
	  ftbbs_msg("不允许上传".$extName."类型的文件","up_photo.php");
	  exit;
    }
	if ($size>$upfilesize){
	  ftbbs_msg("上传的文件最大限制为:".$upfilesize."字节","up_photo.php");
	  exit;
	}
    $uploadfile = $inFolder."/".time().".".$extName; 
    if(@copy($_FILES['userfile']['tmp_name'], $uploadfile) || (function_exists('move_uploaded_file') && @move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)))
    { 
       @unlink($_FILES['userfile']['tmp_name']);
	   $sql="insert into {$tablepre}ftbbs_upload (upload_pic,indate,file_type,upload_size,upload_ext,userid,pic_note,photo_name,sign,bbs_blog_type,clubuser_id) values('".$uploadfile."','".$getnow."',0,'".$size."','".$extName."','".$username."','".$photo_note."','".$photo_name."',".$sign.",2,'".$userid."')";
	   mysql_query($sql);
	   echo "<script>window.location.href='up_photo.php?success=Y&pic=".$uploadfile."';</script>";
	   exit;
    }
} 
else{ 
	ftbbs_msg("上传文件不能为空","up_photo.php");
	exit;
} 
$db->close(); 
?>
