2009年4月16日星期四

目录监控脚本程序[PHP]


/**
*
* 目录监控
*
*
**/
set_time_limit(0);
define('M_PATH','.'); //设置监控的目录,当前目录为'.',上一级目录为'..',也可以设置绝对路径,后面不要加斜杠
define('M_LOG','../m.log');
//设置存储log的路径,可以放置在任意位置
$file_list = array();
function
record_md5($dir){
global $file_list;

if(is_dir($dir)){

$file=scandir($dir);

foreach($file as $f){

if($f!='.' &&
$f!='..'){

$path = $dir.'/'.$f;


if(is_dir($path)){


record_md5($path);


}else{


$file_list[$path]=md5_file($path);


}

}

}

}
}
record_md5(M_PATH);
if(file_exists(M_LOG)){

$log = unserialize(file_get_contents(M_LOG));
}else{

$log =
array();
}
file_put_contents(M_LOG,serialize($file_list));
if(count($file_list)
> 0 ){
foreach($file_list as $file =>
$md5){

if(!isset($log[$file])){

print '新增:'.$file.'
';

}else{

if($log[$file] !=
$md5){

print '修改:'.$file."/>";

unset($log[$file]);


}else{

unset($log[$file]);


}
}



}
}
if(count($log)>0){
foreach($log as
$file => $md5){
print "删除:".$file."/>";
}
}
?>


e-Rest Search Engine
Upimg Image Hosting
Free Online Games
Mobile Player Forum
iPhone Wallpapers
idowns!
Wood Furnitures
Free Article Net
Chinese Trends
IT Info Rss
VIRGO唯格中国
Guangzhou Yiren Fashion

没有评论: