Home > php教程 > php手册 > PHP实现查找指定目录下指定的文件

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:38:56
Original
1130 people have browsed it

<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>

source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template