> 백엔드 개발 > PHP 튜토리얼 > PHP实现查找指定目录下指定的文件_PHP教程

PHP实现查找指定目录下指定的文件_PHP教程

WBOY
풀어 주다: 2016-07-13 17:40:07
원래의
1513명이 탐색했습니다.

<font color="#000000"><font face="NSimsun"><font color="#0000bb"><?php <BR></font><font color="#007700">class </font><font color="#0000bb">document</font></font><font face="NSimsun"><font color="#007700">{ <br></font><font color="#0000bb">private $file_array</font></font><font face="NSimsun"><font color="#007700">=array(); <br></font><font color="#0000bb">private $folder_array</font></font><font face="NSimsun"><font color="#007700">=array(); <br></font><font color="#0000bb">private $all_array</font></font><font face="NSimsun"><font color="#007700">=array(); <br>function </font><font color="#0000bb">search</font><font color="#007700">(</font><font color="#0000bb">$path</font><font color="#007700">,</font><font color="#0000bb">$file</font></font><font face="NSimsun"><font color="#007700">){ <br>       if(</font><font color="#0000bb">is_dir</font><font color="#007700">(</font><font color="#0000bb">$path</font></font><font face="NSimsun"><font color="#007700">)){ <br>       </font><font color="#0000bb">$H</font><font color="#007700">=</font><font color="#0000bb">opendir</font><font color="#007700">(</font><font color="#0000bb">$path</font></font><font face="NSimsun"><font color="#007700">); <br>        while(</font><font color="#0000bb">false</font><font color="#007700">!==(</font><font color="#0000bb">$_file</font><font color="#007700">=</font><font color="#0000bb">readdir</font><font color="#007700">(</font><font color="#0000bb">$H</font></font><font face="NSimsun"><font color="#007700">))){ <br>         if(</font><font color="#0000bb">is_dir</font><font color="#007700">(</font><font color="#0000bb">$path</font><font color="#007700">.</font><font color="#dd0000">"/"</font><font color="#007700">.</font><font color="#0000bb">$_file</font><font color="#007700">)&&</font><font color="#0000bb">$_file</font><font color="#007700">!=</font><font color="#dd0000">"." </font><font color="#007700">&& </font><font color="#0000bb">$_file</font><font color="#007700">!=</font><font color="#dd0000">".." </font><font color="#007700">&& </font><font color="#0000bb">$_file</font><font color="#007700">!==</font><font color="#dd0000">"Thumbs.db"</font></font><font face="NSimsun"><font color="#007700">){ <br>          if(</font><font color="#0000bb">eregi</font><font color="#007700">(</font><font color="#0000bb">$file</font><font color="#007700">,</font><font color="#0000bb">$path</font><font color="#007700">.</font><font color="#dd0000">"/"</font><font color="#007700">.</font><font color="#0000bb">$_file</font></font><font face="NSimsun"><font color="#007700">)){ <br>          </font><font color="#0000bb">array_push</font><font color="#007700">(</font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">folder_array</font><font color="#007700">,</font><font color="#0000bb">$path</font><font color="#007700">.</font><font color="#dd0000">"/"</font><font color="#007700">.</font><font color="#0000bb">$_file</font></font><font face="NSimsun"><font color="#007700">); <br>          } <br>         </font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">search</font><font color="#007700">(</font><font color="#0000bb">$path</font><font color="#007700">.</font><font color="#dd0000">"/"</font><font color="#007700">.</font><font color="#0000bb">$_file</font><font color="#007700">,</font><font color="#0000bb">$file</font></font><font face="NSimsun"><font color="#007700">); <br>         }elseif(</font><font color="#0000bb">is_file</font><font color="#007700">(</font><font color="#0000bb">$path</font><font color="#007700">.</font><font color="#dd0000">"/"</font><font color="#007700">.</font><font color="#0000bb">$_file</font><font color="#007700">)&&</font><font color="#0000bb">$_file</font><font color="#007700">!=</font><font color="#dd0000">"." </font><font color="#007700">&& </font><font color="#0000bb">$_file</font><font color="#007700">!=</font><font color="#dd0000">".." </font><font color="#007700">&& </font><font color="#0000bb">$_file</font><font color="#007700">!==</font><font color="#dd0000">"Thumbs.db"</font></font><font face="NSimsun"><font color="#007700">){ <br>          if(</font><font color="#0000bb">eregi</font><font color="#007700">(</font><font color="#0000bb">$file</font><font color="#007700">,</font><font color="#0000bb">$_file</font></font><font face="NSimsun"><font color="#007700">)){ <br>          </font><font color="#0000bb">array_push</font><font color="#007700">(</font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">file_array</font><font color="#007700">,</font><font color="#0000bb">$path</font><font color="#007700">.</font><font color="#dd0000">"/"</font><font color="#007700">.</font><font color="#0000bb">$_file</font></font><font face="NSimsun"><font color="#007700">); <br>          } <br>         } <br>        } <br>       </font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">all_array</font><font color="#007700">[</font><font color="#dd0000">"folder"</font><font color="#007700">]=</font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">folder_array</font></font><font face="NSimsun"><font color="#007700">; <br>       </font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">all_array</font><font color="#007700">[</font><font color="#dd0000">"file"</font><font color="#007700">]=</font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">file_array</font></font><font face="NSimsun"><font color="#007700">; <br>        return </font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">all_array</font></font><font face="NSimsun"><font color="#007700">; <br>       </font><font color="#0000bb">closedir</font><font color="#007700">(</font><font color="#0000bb">$H</font></font><font face="NSimsun"><font color="#007700">); <br>       }elseif(</font><font color="#0000bb">is_file</font><font color="#007700">(</font><font color="#0000bb">$path</font></font><font face="NSimsun"><font color="#007700">)){ <br>        if(</font><font color="#0000bb">eregi</font><font color="#007700">(</font><font color="#0000bb">$file</font><font color="#007700">,</font><font color="#0000bb">$path</font></font><font face="NSimsun"><font color="#007700">)){ <br>        </font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">all_array</font><font color="#007700">[</font><font color="#dd0000">"file"</font><font color="#007700">]=</font><font color="#0000bb">$path</font></font><font face="NSimsun"><font color="#007700">; <br>        } <br>        return </font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">all_array</font></font><font face="NSimsun"><font color="#007700">; <br>       }else{ <br>        return </font><font color="#0000bb">$this</font><font color="#007700">-></font><font color="#0000bb">error</font><font color="#007700">(</font><font color="#dd0000">"this folder does not exits,please check it out."</font></font><font face="NSimsun"><font color="#007700">); <br>       } <br>} <br>}<br></font><font color="#0000bb">?></font> </font></font>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/486238.htmlTechArticle?php class document { private $file_array =array(); private $folder_array =array(); private $all_array =array(); function search ( $path , $file ){ if( is_dir ( $path )){ $H = open...
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿