The example in this article summarizes the PHP directory traversal method. Share it with everyone for your reference. The details are as follows:
1. Method 1
<?php function myscandir($pathname){ foreach( glob($pathname) as $filename ){ if(is_dir($filename)){ myscandir($filename.'/*'); }else{ echo $filename.'<br/>'; } } } myscandir('D:/wamp/www/exe1/*'); ?>
2. Method 2
<?php function myscandir($path){ $mydir=dir($path); while($file=$mydir->read()){ $p=$path.'/'.$file; if(($file!=".") AND ($file!="..")){ echo $p.'<br>'; } if((is_dir($p)) AND ($file!=".") AND ($file!="..")){ myscandir($p); } } } myscandir(dirname(dirname(__FILE__))); ?>
I hope this article will be helpful to everyone’s PHP programming design.