PHP file traversal small example
Full code:
-
- $dir = "D:workspace";
-
- function list_file($dir = '.'){
- $list = scandir($dir);
- echo '
';
- foreach($list as $file){
- $target = "$dir/$file";
- if ( is_dir($target) && $file != '.' && $file != '..' ) {
- echo "
- $file
";
- list_file($target);
- } else if ( $file != '.' && $file != '..'){
- echo "
- $file
";
- }
- }
- echo '
';
}
list_file($dir);
Copy code
|