Heim  >  Artikel  >  Backend-Entwicklung  >  php实现按文件名搜索文件的远程文件查找器_PHP教程

php实现按文件名搜索文件的远程文件查找器_PHP教程

WBOY
WBOYOriginal
2016-07-13 10:29:58887Durchsuche

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

使用效果:

php实现按文件名搜索文件的远程文件查找器_PHP教程

php文件查找器源码:

复制代码 代码如下:


 
  
  php版文件查找(file search)
 
 
  

  

文件查找(注:区分大小写)


  

路径:


  

查找:


  


  

 

/*
 * 注:区分大小写
 * by: http://www.jb51.net
 */
if(!empty($_POST['path'])&&!empty($_POST['key'])){
 echo "在路径 ".$_POST['path']."/ 中查找 ".$_POST['key']." 的结果为:
";
 $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 " $dirName/$item
\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 " $dirName
\n";
     $GLOBALS['r_dir_num']++;
    }
   }
  }else{
   die("没有此路径!");
  }
 }

 delDirAndFile($_POST['path']);
 echo "


本次共搜索到".$file_num."个文件,文件夹".$dir_num."个
";
 echo "
符合结果的共".$r_file_num."个文件,文件夹".$r_dir_num."个
";
}

?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/768135.htmlTechArticle对于本地,我们可以利用windows自带的查找去进行查找,但是对于线上的话,如查找ftp空间里面文件,本程序是很有用的。 使用效果: php文...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn