This article mainly introduces the PHP traversal and print all the file instances under the specified directory, you need friends can refer to the following
Code as follows: <?php//function: Traverse and print all files function Scan_dir ($dir _name, $dir _flag=1) { static $FILE _count=1 in the specified directory; //record file number 1 directory name does not remember $FILE _count--; //per call Scan_dir () function minus 1 @ $dir _handle=ope Ndir ($dir _name); //Suppress error message display Facilitate custom error display if (! $dir _handle) die ("Directory Open Error! "); while (false!== ($filename =readdir ($dir _handle)) //The file name is ' 0 ', Readdir returns false to determine if the return value is not congruent { $flag = $dir _flag; //Wacky Is_dir ($filename)! $filename This path must be able to find! Returns false if ($filename!= '. ') when $filename does not exist or is not a directory. && $filename!= ' ... ') { $FILE _count++; //Do not record current path and previous path while ($flag >0&&--$flag) //negative number is still true echo '; &NBSP;if (Is_dir ($dir _name. $filename)) //determine if it is a directory { echo ' <strong> '. <a href= ". $dir _name. $filename." > ". $filename." </a></strong><br> "; Scan_dir ($dir _name. $filename. ' /', $dir _flag+1); //$dir _flag logo directory tree hierarchy   else { echo "<a href=". $d Ir_name. $filename. " > ". $filename." </a><br> "; &NBSP} } } closedir ($dir _handle); //close directory handle echo "Total Files:". $FILE _count. ' <br> '; } Scan_dir (' d:wampwwwtestlamp61 '); //the specified file path?>