当前位置: 移动技术网 > IT编程>开发语言>PHP > php搜索文件程序分享

php搜索文件程序分享

2018年04月29日  | 移动技术网IT编程  | 我要评论

疯眼乐队,永春一中校园网,华硕k43

对于本地,我们可以利用windows自带的查找去进行查找,但是对于线上的话,如查找ftp空间里面文件,本程序是很有用的。

php文件查找器源码:

<html>
 <head>
 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
 <title>php版文件查找(file search)</title>
 </head>
 <body>
 <form action="" method="post">
 <p> 文件查找(注:区分大小写)</p>
 <p>路径:<input type="text" name="path" /></p>
 <p>查找:<input type="text" name="key" /></p>
 <p><input type="submit" name="sub" value=" 开 始 " /></p>
 </form>
 </body>
</html>
<?php
/*
 * 注:区分大小写
 * by: http://www.daixiaorui.com
 */
if(!empty($_post['path'])&&!empty($_post['key'])){
 echo "在路径 ".$_post['path']."/ 中查找 ".$_post['key']." 的结果为:<hr/>";
 $file_num = $dir_num = 0;
 $r_file_num = $r_dir_num= 0;
 $findfile = $_post['key'];
 function deldirandfile( $dirname ){ 
 if ( $handle = @opendir( "$dirname" ) ) {
  while ( false !== ( $item = readdir( $handle ) ) ) { 
  if ( $item != "." && $item != ".." ) { 
   if ( is_dir( "$dirname/$item" ) ) { 
   deldirandfile( "$dirname/$item" );
   } else { 
   $globals['file_num']++;
   if(strstr($item,$globals['findfile'])){
    echo " <span><b> $dirname/$item </b></span><br />\n";
    $globals['r_file_num']++;
   }
   } 
  }
  }
  closedir( $handle ); 
  $globals['dir_num']++;
  if(strstr($dirname,$globals['findfile'])){
  $loop = explode($globals['findfile'],$dirname);
  $countarr = count($loop)-1;
  if(empty($loop[$countarr])){
   echo " <span style='color:#297c79;'><b> $dirname </b></span><br />\n";
   $globals['r_dir_num']++;
  }
  }
 }else{
  die("没有此路径!");
 }
 }

 deldirandfile($_post['path']);
 echo "<hr/>本次共搜索到".$file_num."个文件,文件夹".$dir_num."个<br/>";
 echo "<hr/>符合结果的共".$r_file_num."个文件,文件夹".$r_dir_num."个<br/>";
}

?>

以上就是php文件查找器程序,可以搜索本地文件,便于操作,希望对大家的学习有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网