The example in this article describes how PHP uses a recursive method to list all files in the current directory. Share it with everyone for your reference. The specific implementation method is as follows:
<?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 />?>
I hope this article will be helpful to everyone’s PHP programming design.