Introducing a code that can traverse all files and subfolders in a directory for reference by beginners.
Example: <?php /** * 遍历目录下所有文件及子文件夹 * edit bbs.it-home.org */ function read_all_dir ( $dir ) { $result = array(); $handle = opendir($dir); if ( $handle ) { while ( ( $file = readdir ( $handle ) ) !== false ) { if ( $file != '.' && $file != '..') { $cur_path = $dir . DIRECTORY_SEPARATOR . $file; if ( is_dir ( $cur_path ) ) { $result['dir'][$cur_path] = read_all_dir ( $cur_path ); } else { $result['file'][] = $cur_path; } } } closedir($handle); } return $result; } ?> Copy after login The code is not complicated. If you are interested, you can find a few directories and test it yourself. |