<?php
header("content-type:text/html;charset=utf-8");
session_start();
error_reporting(0);
if(!isset($_SESSION['admin_name'])){
   exit; 
}
date_default_timezone_set("PRC");
include "../sql.php";
$admin_logo=$_POST['logo'];
$himage=$_POST['himage'];
$file_tmp=$_FILES['tupian']['tmp_name'];
$file_old_name=$_FILES['tupian']['name'];
$file_exp=explode(".",$file_old_name);
$file_pop=array_pop($file_exp);
$file_rand=date("YmdHis",time()).mt_rand().".".$file_pop;
$file_new="../image/".$file_rand;
if($_FILES['tupian']['error']===4){
    $logo_sql="update admin_logo set logo='{$admin_logo}',image='{$himage}'";
    if(mysql_query($logo_sql)){
        echo "<script>alert('修改成功！');</script>";
    }else{
        echo "<script>alert('修改失败！');</script>";
    }
}elseif($_FILES['tupian']['error']===0){
    if(move_uploaded_file($file_tmp,$file_new)){
            $logo_sql="update admin_logo set logo='{$admin_logo}',image='{$file_rand}'";
        if(mysql_query($logo_sql)){
            unlink("../image/".$himage);
            echo "<script>alert('修改成功！');</script>";
        }else{
            echo "<script>alert('修改失败！');</script>";
        }
    }
}

echo "<script>location='../index.php';</script>";

?>