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

$username=get_cookie('username');
$inFolder="userheadimg";
$upfiletype="gif|jpg";
$upfilesize=51200;

$userlogin=checkuserlogin();
if ($userlogin=="N"){
   echo "你还没有登录或非法操作,<a href=userimg.php>重新上传</a>";
   exit;
}
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=userimg.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 "您上传的文件有问题,<a href=userimg.php>返回重新上传</a>";
	  exit;
	}
    if (!in_array($extName,explode("|", $upfiletype))){
	  echo "不允许上传".$extName."类型的文件,<a href=userimg.php>返回重新上传</a>";
	  exit;
    }
	if ($size>$upfilesize){
	  echo "上传的文件最大限制为:".$upfilesize."字节,<a href=userimg.php>返回重新上传</a>";
	  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']);
		$insql = "update {$tablepre}clubuser set userimg='".time().".".$extName."' where clubuser_name='".$username."'";
        mysql_query($insql);
        echo "<script language='javascript'>history.go(-1);</script>";
	    exit;
    }
} 
else{ 
        echo "<script language='javascript'>";
        echo "alert('上传文件不能为空!');history.go(-1);";
		echo "</script>";
	    exit;
} 
$db->close(); 
?>