This article mainly introduces the PHP traversal folder of all the files and subfolders examples, here are two methods, the need for friends can refer to the following
Traverse the directory and the result is stored in an array. Support PHP4 and above. PHP5 can replace the while loop with the Scandir () function later. Code as follows: <?php/** * @param string $dir * @return Array/function My_scandir ($dir) { $files = array (); &nbs P;if ($handle = Opendir ($dir)) { while ($file = Readdir ($handle))!== false) { &NBSP;IF ( $file!= "..." && $file!= ".") { if Is_dir ($dir. "/" . $file)) { $files [$file] = My_scandir ($dir. "/" . $file); } else { $files [] = $file; } &nbs P;} } Closedir ($handle); return $files; &NBSP} function My_scandir1 ($dir) { $files = array (); $dir _list = Scandir ($dir); foreach ($dir _ List as $file) { if ($file!= "..." && $file!= ".") { if is_dir ($dir. "/" . $file)) { $files [$file] = My_scandir1($dir. "/" . $file);   else { $files [] = $file; } } &nbs P return $files; } $result = My_scandir ('./'); $result = My_scandir1 ('./');?> Another implementation method code is as follows: function Fetchdir ($dir) { foreach (Glob $dir. ' * ') as $file) { echo $file, "n"; &n Bsp if (Is_dir ($file)) { &NBSP ; Fetchdir ($file); } } } Fetchdir ("D:wampwwwany"); can also replace ' * ' with directory_separator. ' * ', replace ' n ' with Php_eol, so you can cross the platform.