<body leftmargin="0" topmargin="0" bgcolor=#E9F5F5>
<style type="text/css">*{font-size:12px;}</style>
<?php 
require_once(dirname(__FILE__)."/../admin_inc.php");
checkPower();
$act = getForm("act", "get");
$isslide = getForm("is");
if ($isslide == "slide") {
	$up_formPath="../../pic/slide/";
} else if ($isslide == "zt") {
	$up_formPath="../../pic/zt/";
} else if ($isslide == "news") {
	$sitePic="newspic/".date("Y")."/".date("n");$up_formPath="../../pic/".$sitePic."/";
} else {
	$sitePic=sitePic."/".date("Y")."/".date("n");$up_formPath="../../pic/".$sitePic."/";
}
switch ($act){
	case "up" : upload();break;
}

function upload() {
	global $up_formPath,$isslide,$sitePic;
    $uptypes = array('image/jpg', 'image/jpeg', 'image/png', 'image/pjpeg', 'image/gif', 'image/bmp', 'image/x-png'); 
    $max_file_size = 2000000;     //上传文件大小限制, 单位BYTE 
    if ($_SERVER['REQUEST_METHOD'] == 'POST'){ 
        if (!is_uploaded_file($_FILES["file1"]['tmp_name'])) { 
		    exit("<table><tr><td bgcolor=#E9F5F5>请先选择你要上传的文件　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>"); 
        } 
        $file = $_FILES["file1"]; 
        if ($max_file_size < $file["size"]) { 
	        exit("<table><tr><td bgcolor=#E9F5F5>文件大小超过了限制　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>"); 
        } 
        if (!in_array($file["type"], $uptypes)) { 
	        exit("<table><tr><td bgcolor=#E9F5F5>文件格式不正确　[ <a href=# onclick=history.go(-1)>重新上传</a> ]</td></tr></table>"); 
        } 
        if (!file_exists($up_formPath)) { 
            mkdirs($up_formPath); 
        } 
        $filename = $file["tmp_name"]; 
        $pinfo = pathinfo($file["name"]); 
        $ftype = $pinfo['extension']; 
        $destination = $up_formPath.time().".".$ftype; 
        if (file_exists($destination)) { 
            exit("同名文件已经存在了"); 
        } 
        if (!move_uploaded_file ($filename, $destination)) { 
            exit("移动文件出错"); 
        } 
        $pinfo = pathinfo($destination); 
        $fname = $pinfo['basename'];
	    if ($isslide == "slide" || $isslide == "zt") {
		    echo "<script>try{parent.onUploadBack('".$fname."')}catch(e){alert('未定义上传回调函数onUploadBack(string filename)')}</script>";
	    } else {
		    echo "<script>parent.document.getElementById('m_pic').value='pic/".$sitePic."/".$fname."'</script>";
	    }
	    echo "<table><tr><td bgcolor=#E9F5F5><font color=red >".$isslide."上传成功![ <a href=# onclick=history.go(-1)>重新上传</a> ]</font></td></tr></table>";
    } 
}
?>