<?php 
require "../Run.php";
require "../include/class/simage.class.php";
echo head('头像管理');
echo '<div class="title">
<a href="userInfo_mod.php">
<<返回</a>
</div>';
if($_GET['type']=='upload'){
/*文件处理机制问题暂时停止此功能*/
date_default_timezone_set('PRC');
$D=date(YmdHis);
$filetype=strtolower(substr(strrchr($_FILES['head']['name'],"."),1));
$newname=$id.'_'.$name.".".$filetype;
$uploaddir=$_SERVER['DOCUMENT_ROOT'].'/user/head/';
$UploadFile=$uploaddir.$newname;
$UploadPath=Addslashes(dirname($PATH_TRANSLATED))."/head";
$FileName=$uploadPath.$UploadFile_name;
/*上传文件检测*/
$error = $_FILES['head']['error'];
if($error == 1){
echo '上传失败：你上传的文件超过了php的系统约定值！';
}elseif($error == 2){
echo '上传失败：上传的文件超过了表单设置的最大值！';
}elseif($error == 3){
echo '上传失败：文件只有部分被上传';
}elseif($error == 5){
echo '上传失败：发生未知错误！';
}elseif($error == 4){
$pic=NULL;
}else{
$allowtype=array("jpeg","png","jpg","gif","JPEG","PNG","JPG","GIF");
if(!in_array($filetype,$allowtype)){
echo '<div class=\"tip\">上传失败：您上传的文件类型不是图片！</div>';
}else{
if(move_uploaded_file($_FILES['head']['tmp_name'],$UploadFile)){
echo "<div class=\"tip\">太好咯！我的头像成功上传喽，快去看看吧！</div>";
$headpath="head/".$newname;
$sheadpath100="head/shead_100/".$newname;
$sheadpath60="head/shead_60/".$newname;
$headlink='http://'.$_SERVER["HTTP_HOST"].'/user/head/shead_100/'.$newname;
//修改数据库
$sql="UPDATE user SET head='{$headlink}' WHERE id='{$id}'";
mysql_query($sql);
//生成缩略图
simage($headpath,100,100,$sheadpath100,$filetype);
simage($headpath,60,60,$sheadpath60,$filetype);
}else{
echo "哎呀！头像上传失败，请稍后重试或联系管理员！";
$pic==NULL;
                    }
                }
            }
        }
echo '<div class="tip">请选择本地图片上传图片作为头像，您的头像将被缩放为200X200的头像，当然，所以请尽量选择此规格的图片！</div>
<div class="subtitle"><form  name="form1" enctype="multipart/form-data" method="post"
action="head.php?type=upload&"><input type="file" name="head" id="fileField">
<br>
<input type="submit" value="上传头像"
></form>
</div>';
echo footer(1);
?>