Home > Backend Development > PHP Tutorial > PHP implementation to find the specified file in the specified directory_PHP tutorial

PHP implementation to find the specified file in the specified directory_PHP tutorial

WBOY
Release: 2016-07-13 17:40:07
Original
1507 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>

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...
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template