www.gusucode.com > 监控设备公司网站源码程序 > 监控设备公司网站源码程序/code/base/appfile.php

    <?php
define("ROOTPATH", "../");
include(ROOTPATH."includes/common.inc.php");
set_time_limit(0);

//密钥校验
$k=md5(strrev($dbUser.$dbPass));
$h=$_SERVER["HTTP_REFERER"];
$t=$_POST["t"];
$m=$_POST["m"];
$act=$_POST["act"];
$path=$_POST["path"];

$md5=md5($k.$t);
if($m!=$md5){
	echo "ERROR: 安全性校验错误";
	exit;
}


//文件上传
if($act=="upload"){

		$file=$_FILES["file"];
		$r_size=$_POST["r_size"];

		if ($_FILES["file"]["ERROR"] > 0){
		  echo "ERROR:".$_FILES["file"]["ERROR"];
		  exit;
		}else{
			if($_FILES["file"]["size"]!=$r_size){
				echo "ERROR:上传文件错误,文件大小和原文件不匹配";
				@write_log("app.log",date("Y-m-d H:i:s",time())." ERROR: 上传文件错误,文件大小和原文件不匹配\n",FILE_APPEND);
				exit;
			}

			//检查目录名
			$ToPath="../effect/source/bg";
			$Tofile=$ToPath."/".$_FILES["file"]["name"];
			
			
			if(!is_writable($ToPath)){
				echo "ERROR:".$ToPath." 目录不可写,请设置目录属性为可写";
				@write_log("app.log",date("Y-m-d H:i:s",time())." ERROR: ".$ToPath." 目录不可写,请设置目录属性为可写\n",FILE_APPEND);
				exit;
			}

			if(file_exists($Tofile) && !is_writable($Tofile)){
				echo "ERROR:".$Tofile." 文件不能覆盖,请设置文件属性为可写";
				@write_log("app.log",date("Y-m-d H:i:s",time())." ERROR: ".$Tofile." 文件不能覆盖,请设置文件属性为可写\n",FILE_APPEND);
				exit;
			}
			

			//复制文件
			copy($_FILES["file"]["tmp_name"],$Tofile);
			
			switch($_FILES["file"]["type"]){
			
				case "application/octet-stream":
					@chmod($Tofile,0755);
				break;

				default:
					@chmod($Tofile,0666);
				break;
			}

			echo "OK";
			@write_log("app.log",date("Y-m-d H:i:s",time())." 安装成功: ".$Tofile."\n",FILE_APPEND);
			exit;
		}


}


function write_log($logfile,$logtext,$mode){
	if(intval(substr(phpversion(),0,1))>=5){
		@file_put_contents($logfile,$logtext,$mode);
	}else{
		$fp = fopen($logfile,"a");
		fwrite($fp,$logtext);
		fclose($fp);
	}
}


?>