PHP function to traverse and display all directories and files in a folder without paging code_PHP Tutorial

WBOY
Release: 2016-07-21 15:49:06
Original
785 people have browsed it

 <br><?php <BR>/************************ <BR>A simple directory recursive function<BR>The first implementation method: use dir to return the object<BR>***** ********************/ <BR>function tree($directory) <BR>{ <BR>$mydir=dir($directory); <BR>echo "<ul>n"; <br>while($file=$mydir->read()){ <br>if((is_dir("$directory/$file")) AND ($file!=".") AND ($file!="..")) <br>{echo "<li><font color="#ff00cc"><b>$file</b></font></li>n"; <br>tree("$directory/$file"); <br>} <br>else <br>echo "<li>$file</li>n"; <br>} <br>echo "</ul>n"; <br>$mydir->close(); <br>} <br>//开始运行 <br>echo "<h2>目录为粉红色</h2><br>n"; <br>tree("F:/"); <br>/*********************** <br>The second implementation method: use the readdir() function <br>************ **************/ <br>function listDir($dir){ <br>if(is_dir($dir)){ <br>if ($dh = opendir($dir)) { <br>while (($file= readdir($dh)) !== false){ <br>if((is_dir($dir."/".$file)) && $file!="." && $file!=".."){ <br>echo "<b><font color='red'>文件名:</font></b>",$file,"<br><hr>"; <br>listDir($dir."/".$file."/"); <br>}else{ <br>if($file!="." && $file!=".."){ <br>echo $file."<br>"; <br>} <br>} <br>} <br>closedir($dh); <br>} <br>} <br>} <br>//开始运行 <br>listDir(E:/常用软件备份/); <br>?> <br>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/319576.htmlTechArticlepre ?php /************************ The first way to implement a simple directory recursive function: use dir to return the object ************** ***********/ function tree($directory) { $mydir=dir($direct...
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