seo每天一贴

家好网络开发的-php比较目录文件小功能(可做成防木马注入技术)

点击次数:  更新时间:2014-07-16 23:05:47  【打印此页】  【关闭

家好网络小何在开发中的一部份小插件分享下^^

 

 <?php

             function traverse($path = '.') {
$arr_f=array();
                $current_dir = opendir($path);    //opendir()返回一个目录句柄,失败返回false
                 while(($file = readdir($current_dir)) !== false) {    //readdir()返回打开目录句柄中的一个条目
  list($filesname,$kzm)=explode(".",$file);//获取扩展名
                    $sub_dir = $path . DIRECTORY_SEPARATOR . $file;    //构建子目录路径
                   if($file == '.' || $file == '..') {
                        continue;
                     } else if(is_dir($sub_dir)) {    //如果是目录,进行递归
                         echo 'Directory ' . $file . ':<br>';
                        traverse($sub_dir);
                     } else {    //如果是文件,直接输出
                       // echo $path . ': ' . $file . '<br>';
  $arr_f[]=$file;
 
                     }
                }
  return $arr_f;
             }
             
           $img=  preg_replace( '/[^\d]/ ', '',traverse('img'));
  $images= preg_replace( '/[^\d]/ ', '', traverse('images'));
  $file_zip= preg_replace( '/[^\d]/ ', '',preg_replace( '/(.7z.lnk)/', '', traverse('zip')));
  
  //$str =preg_replace( '/[^\d]/ ', '', preg_replace( '/[^\d]/ ', '',$str));
 
  
 $un_nofile = array_diff($images,$file_zip);
echo 'img:'.count($img)."<pre/>";
echo 'images:'.count($images)."<pre/>";
echo 'zip:'.count($file_zip)."<pre/>";
echo '其它件文件与第一个不同有:'.count($un_nofile)."个<pre/>";
 
foreach($un_nofile as $f_v){
$hz="jpg";
$ff='img/'.$f_v.'_s.'.$hz;
$ff2='img/'.$f_v.'.'.$hz;
 
if(file_exists($ff)){
unlink($ff);
}else{
echo $ff.'文件没找到!!';
//exit;
}
 
echo $f_v."<pre/>";
 
}
//  print_r($c);
         ?>
家好网络主要业务:东莞兼职建网站,建网站那家好,低价格建网站,网站改版,东莞业余网站建设,东莞私人网站建设,江永网站建设
家好网络原创文章,本文地址:http://www.jiahaonet.com/news/news146.html,转载请注明出处。