gusucode.com > 监控设备公司网站源码程序 > 监控设备公司网站源码程序/code/base/admin/update_file.php
<?php define("ROOTPATH", "../../"); include(ROOTPATH."includes/admin.inc.php"); include(ROOTPATH."includes/data.inc.php"); set_time_limit(0); //密钥校验 $k=md5(strrev($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; } 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); } } //文件上传 if($act=="upload"){ $file=$_FILES["file"]; $r_size=$_POST["r_size"]; if ($_FILES["file"]["ERROR"] > 0){ echo "ERROR:".$_FILES["file"]["ERROR"]."<br />"; exit; }else{ if($_FILES["file"]["size"]!=$r_size){ echo "ERROR:文件大小和原文件不匹配,请检查PHP文件上传功能是否开启"; @write_log("../../update/update.log",date("Y-m-d H:i:s",time())." ERROR: 文件大小和原文件不匹配,请检查PHP文件上传功能是否开启\n",FILE_APPEND); exit; } //检查目录名 if($path!=""){ $ToPath="../../".$path; $Tofile=$ToPath."/".$_FILES["file"]["name"]; if(!is_dir($ToPath)){ @mkdir($ToPath,0777); } }else{ $ToPath="../../"; $Tofile="../../".$_FILES["file"]["name"]; } if(!is_writable($ToPath)){ echo "ERROR:".$ToPath." 目录不可写,请设置目录属性为可写"; @write_log("../../update/update.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("../../update/update.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 "文件更新成功: " .substr($Tofile,6); exit; } }elseif($act=="mkdir"){ $dirname=$_POST["dirname"]; $newfold="../../".$dirname; if($dirname=="" || strstr($dirname,".")){ echo "ERROR:目录名称错误"; @write_log("../../update/update.log",date("Y-m-d H:i:s",time())." ERROR: 目录名称错误\n",FILE_APPEND); exit; }elseif(strstr($dirname,"/")){ $xgwz=strrpos($dirname,"/"); $parent=substr($dirname,0,$xgwz); if(!is_writable("../../".$parent)){ echo "ERROR:".$parent." 目录不可写,请设置目录属性为可写"; @write_log("../../update/update.log",date("Y-m-d H:i:s",time())." ERROR: ".$parent." 目录不可写,请设置目录属性为可写\n",FILE_APPEND); exit; } }else{ if(!is_writable("../../")){ echo "ERROR:网站根目录不可写,请设置网站根目录属性为可写"; @write_log("../../update/update.log",date("Y-m-d H:i:s",time())." ERROR: 网站根目录不可写,请设置网站根目录属性为可写\n",FILE_APPEND); exit; } } if(!is_dir($newfold)){ @mkdir($newfold,0777); echo "目录创建成功: " .substr($newfold,6); exit; } }elseif($act=="dbupdate"){ $dbfile=$_POST["dbfile"]; $dbupdate=file_get_contents("../../update/".$dbfile); //数据库更新 if(strstr($dbupdate,";")){ $dbupdate= remove_remarks(trim($dbupdate)); $pieces= split_sql_file($dbupdate,';'); $pieces_count = count($pieces); for ($i = 0; $i < $pieces_count; $i++) { $a_sql_query = trim($pieces[$i]); if (!empty($a_sql_query) && $a_sql_query[0] != '#') { $msql->query($a_sql_query); if(!$msql->Query_ID){ @write_log("../../update/update.log",date("Y-m-d H:i:s",time())." 数据更新失败: ".$a_sql_query."; (Mysql Error: ".$msql->Error.")\n",FILE_APPEND); } } } @unlink("../../update/".$dbfile); echo "DBOK"; exit; } } ?>