php监听文件路径_PHP监控服务器文件目录

/**

*

*  目录监控

*

*  @author 郭瑞超 (grc1988#gmail.com)

*  @date 2009-04-15

*  @license BSD

*  @package common

*  @version 0.0.1

*

**/

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."
";

}

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值