在上传文件之后安装之前校验文件的工具

<?php

if(!$discuzfiles = @file('./source/admincp/discuzfiles.md5')) {
	echo "source\admincp\discuzfiles.md5文件不存在,请上传!";
}
$md5data = array();
checkfiles('./', '', 0);
checkfiles('config/', '', 1, 'config_global.php,config_ucenter.php');
checkfiles('data/', '\.xml', 0);
checkfiles('data/avatar/', '\.htm', 0);
checkfiles('data/cache/', '\.htm', 0);
checkfiles('data/ipdata/', '\.htm|\.dat', 0);
checkfiles('data/template/', '\.htm', 0);
checkfiles('data/threadcache/', '\.htm', 0);
checkfiles('template/', '');
checkfiles('api/', '');
checkfiles('source/', '', 1, 'discuzfiles.md5,plugin');
checkfiles('static/', '');
checkfiles('archiver/', '');
checkfiles('uc_client/', '\.php|\.htm', 0);
checkfiles('uc_client/data/', '\.htm');
checkfiles('uc_client/control/', '\.php|\.htm');
checkfiles('uc_client/model/', '\.php|\.htm');
checkfiles('uc_client/lib/', '\.php|\.htm');
checkfiles('uc_server/', '\.php|\.htm|\.txt|\.xml', 0);
checkfiles('uc_server/data/', '\.htm');
checkfiles('uc_server/api/', '\.php|\.htm');
checkfiles('uc_server/control/', '\.php|\.htm|\.md5');
checkfiles('uc_server/model/', '\.php|\.htm');
checkfiles('uc_server/lib/', '\.php|\.htm');
checkfiles('uc_server/plugin/', '\.php|\.htm|\.xml');
checkfiles('uc_server/upgrade/', '\.php');
checkfiles('uc_server/images/', '\..+?');
checkfiles('uc_server/js/', '\.js|\.htm');
checkfiles('uc_server/release/', '\.php');
checkfiles('uc_server/view/', '\.php|\.htm');

foreach($discuzfiles as $line) {
	$file = trim(substr($line, 34));
	$md5datanew[$file] = substr($line, 0, 32);
	if($md5datanew[$file] != $md5data[$file]) {
		$modifylist[$file] = $md5data[$file];
	}
	$md5datanew[$file] = $md5data[$file];
}

$dellist = @array_diff_assoc($md5datanew, $md5data);
$modifylist = array_diff_assoc($modifylist, $dellist);
$num = count($dellist);
echo "<div style='float:left;'><h2>检查完毕,缺少".$num."个文件:</h2><br />";
foreach ($dellist as $names => $v) {	
	echo "<b>".$names."</b><br />";
}
if($names){
	echo "<br /><br />请上传上述文件,以确保站点正常运行!<br /><br /><br /></div>";
}
echo "<div style='float:left;margin-left:50px;'><h2>以下文件可能没有上传完整!</h2><br />";
foreach($modifylist as $lose => $vs){
	echo "<b>".$lose."</b><br />";
}
echo "<br /><br />请检查FTP工具或网络状况是否正常,然后重新上传这些文件。</div>";
function checkfiles($currentdir, $ext = '', $sub = 1, $skip = '') {
	global $md5data;
	$path = realpath('./');
	$dir = @opendir($path."/".$currentdir);
	$exts = '/('.$ext.')$/i';
	$skips = explode(',', $skip);

	while($entry = @readdir($dir)) {
		$file = $currentdir.$entry;
		if($entry != '.' && $entry != '..' && (($ext && preg_match($exts, $entry) || !$ext) || $sub && is_dir($file)) && !in_array($entry, $skips)) {
			if($sub && is_dir($file)) {
				checkfiles($file.'/', $ext, $sub, $skip);
			} else {
				if(is_dir($file)) {
					$md5data[$file] = md5($file);
				} else {
					$md5data[$file] = md5_file($file);
				}
			}
		}
	}
}
adds
?>
这个脚本保存后可以在上传文件之后安装之前校验文件。

Comments

No comments yet. Why don’t you start the discussion?

发表回复