xml.php 生成要同步的源码
<?php
error_reporting(0);
@set_time_limit(300);
@date_default_timezone_set('UTC');
header("Content-type:text/xml;");
$XML ="<files build='172945' codepage='65001' xmlns:dt='urn:schemas-microsoft-com:datatypes'>";
foreach(array_while(my_scandir(".")) as $v){
$filename = mb_substr($v,2);
$is_filename = strrchr($filename,'.'); //文件的扩展名
if(!empty($is_filename) && in_array($is_filename , [".php", ".txt", ".html", ".htm"]) ){
$html = file_get_contents(dirname(__FILE__)."/".$filename);
$base64 = base64_encode($html);
$XML.= "<file name='".$filename."' crc32='".crc32($base64.$filename)."' dt:dt='bin.base64'>".$base64."</file>";
}
}
$XML.= "</files>";
echo $XML;
exit;
//遍历当前文件夹展示所有的文件和目录
function my_scandir($dir){
$files=array();
if(is_dir($dir)){
if($handle=opendir($dir)){
while(($file=readdir($handle))!==false){
if($file!='.' && $file!=".."){
if(is_dir($dir."/".$file)){
$files[$file]=my_scandir($dir."/".$file);
}else{
$files[]=$dir."/".$file;
}
}
}
}
}
closedir($handle);
return $files;
}
//PHP多维数组转为一维数组的方法
function array_while($array)
{
static $res_arr = [];
foreach ($array as $v) {
if (is_array($v)) {
array_while($v);
} else {
$res_arr[] = $v;
}
}
return $res_arr;
}
?>
up_xml.php
<?php
error_reporting(0);
@set_time_limit(300);
@date_default_timezone_set('UTC');
header('Content-type: text/html; charset=utf-8');
ob_start();
install();
die("完成");
function GetHttpContent($url) {
$r = null;
if (function_exists("curl_init") && function_exists('curl_exec')) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
$httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
$httpheader[] = "Connection:close";
$httpheader[] = "code:key_ture";
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
if(ini_get("safe_mode")==false && ini_get("open_basedir")==false){
curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
}
if(extension_loaded('zlib')){
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
}
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
$opt[CURLOPT_USERAGENT]=$_SERVER['HTTP_USER_AGENT'] . ' AppCentre/2099-01-01 ';
curl_setopt_array($ch,$opt);
$r = curl_exec($ch);
curl_close($ch);
} elseif (ini_get("allow_url_fopen")) {
if(function_exists('ini_set'))ini_set('default_socket_timeout',300);
$opt['header']='User-Agent: AppCentre/2099-01-01 ' . $_SERVER['HTTP_USER_AGENT'];
$r = file_get_contents((extension_loaded('zlib')?'compress.zlib://':'') . $url, false, stream_context_create(array('http' => $opt)));
}
return $r;
}
function install(){
$d=dirname(__FILE__);
if(substr((string)decoct(fileperms($d)),-3)<>'755'&&substr((string)decoct(fileperms($d)),-3)<>'777'){
echo "<p>警告:安装目录权限" . $d . "不是0755或是0777,可能无法运行在线安装程序.</p>";
}
echo "<p>正在努力地下载数据包...</p>";
ob_flush();
$GLOBALS['xml']=GetHttpContent('http://127.0.0.1/xml.php');
echo "<p>正在解压和安装文件...</p>";
ob_flush();
if ($GLOBALS['xml']) {
$xml = simplexml_load_string($GLOBALS['xml'],'SimpleXMLElement');
$old = umask(0);
foreach ($xml->file as $f) {
$filename=str_replace('\\','/',$f->attributes());
$dirname= dirname($filename);
mkdir($dirname,0755,true);
$fn=$filename;
file_put_contents($fn,base64_decode($f));
}
umask($old);
} else {
return false;
}
}
?>
这代码也是看某个博客在线安装的,挺好用的,可以自己在更新网站代码上使用,不用一个个的去上传