php目录监控

浏览:781 发布日期:2017/03/02 分类:技术分享
<·?·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.'
';
·}
·}else{
·echo '未删除';
·}
最佳答案
评论() 相关
后面还有条评论,点击查看>>