Home >Backend Development >PHP Tutorial >PHP file search program sharing_php skills

PHP file search program sharing_php skills

WBOY
WBOYOriginal
2016-05-16 20:05:38862browse

For local, we can use the search that comes with Windows to search, but for online, such as searching for files in ftp space, this program is very useful.

php file finder source code:

<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>
<&#63;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/>";
}

&#63;>

The above is the PHP file finder program, which can search local files for easy operation. I hope it will be helpful to everyone's learning.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn