Home > php教程 > php手册 > PHP使用递归方式列出当前目录下所有文件的方法,

PHP使用递归方式列出当前目录下所有文件的方法,

WBOY
Release: 2016-06-13 09:02:39
Original
947 people have browsed it

PHP使用递归方式列出当前目录下所有文件的方法,

本文实例讲述了PHP使用递归方式列出当前目录下所有文件的方法。分享给大家供大家参考。具体实现方法如下:

<&#63;php<br />function filelist($pathname,$i){<br />//定义一个filelist函数<br />    $dir=opendir($pathname);<br />    while(($file=readdir($dir))!== false){<br />        $fname=$pathname."/".$file;<br />        if(is_dir($fname)&&$file!="."&&$file!=".."){<br />            for($tmp=0;$tmp<=8*$i;$tmp++)<br />                echo " ";<br />            echo '<input type="checkbox" name="Bike">';<br />            echo "is directory:".$fname."<br>";<br />            filelist($fname,$i+1);<br />        }elseif($file!="."&&$file!=".."){<br />            for($tmp=0;$tmp<=8*$i;$tmp++)<br />                echo " ";<br />            echo '<input type="checkbox" name="Bike">';<br />            echo $fname."<br>";<br />        }<br />    }<br />    chdir("..");<br />    closedir($dir);<br />}<br />filelist("/home/zhou/shell",0);<br />//列出/home/zhou/shell下的所有文件及目录。<br />&#63;>
Copy after login

希望本文所述对大家的php程序设计有所帮助。

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