<?php //检查文件是否写 php结束符号 encode_check('E:\www\encode\l002.yidong.9885.com'); /*加密检查*/ function encode_check($dir) { $php_list = find_all_php($dir); //遍历所有php文件检查是否写 结束 foreach( $php_list as $php ) { $content = file_get_contents($php); if( strpos($content,'?>') === false ) { echo "error::::{$php}\r\n"; $content .= "\r\n?>"; //此处自动补足尾部结束符 file_put_contents($php,$content); } } } //找出所有php文件 function find_all_php($dir) { $file_list = array(); $list = listFile($dir); foreach( $list as $file) { //var_dump($file); if( $file['type'] == 'dir' ) { list_dir($file['pathname']."\\",$file_list); } else { if( $file['ext'] == 'php' ) { $file_list[] = $file['pathname']; } } } return $file_list; } //递归获取php文件 function list_dir($path,&$file_list) { $list = listFile($path); foreach( $list as $file) { //echo $file['pathname']."\r\n"; if( $file['type'] == 'dir' ) { //echo $file['pathname']."\r\n"; list_dir($file['pathname']."\\",$file_list); } else { if( $file['ext'] == 'php' ) { $file_list[] = $file['pathname']; } } } } //列出目录下的所有文件 function listFile($pathname,$pattern='*') { $guid = md5($pathname.$pattern); $dir = array(); $list = glob($pathname.$pattern); foreach ($list as $i=>$file){ $dir[$i]['filename'] = basename($file); $dir[$i]['pathname'] = realpath($file); $dir[$i]['type'] = filetype($file); $dir[$i]['ext'] = is_file($file)?strtolower(substr(strrchr(basename($file), '.'),1)):''; } return $dir; } ?>
php结束符号?>目录递归检查,自动补全修复
2,865 评论(
0 )
暂无评论
写评论