Home  >  Article  >  Backend Development  >  PHP file traversal small example

PHP file traversal small example

WBOY
WBOYOriginal
2016-07-25 09:11:51809browse

PHP file traversal small example

Full code:

  1. $dir = "D:workspace";
  2. function list_file($dir = '.'){
  3. $list = scandir($dir);
  4. echo '
      ';
    1. foreach($list as $file){
    2. $target = "$dir/$file";
    3. if ( is_dir($target) && $file != '.' && $file != '..' ) {
    4. echo "
    5. $file
    6. ";
    7. list_file($target);
    8. } else if ( $file != '.' && $file != '..'){
    9. echo "
    10. $file
    11. ";
    12. }
    13. }
    14. echo '
    ';
  5. }
  6. list_file($dir);
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn