Home >Backend Development >PHP Tutorial >PHP directory traversal code

PHP directory traversal code

WBOY
WBOYOriginal
2016-07-25 08:42:321014browse

PHP directory traversal

  1. //php directory traversal
  2. function showDetail($dirname){
  3. $ds = opendir($dirname);
  4. while($file = readdir($ds) ){
  5. $path = $dirname."/".$file;
  6. if($file != "." && $file != ".."){ //This is a trap
  7. if(is_dir($path) ){
  8. showDetail($path); //Recursive call, if the directory is read, continue reading
  9. }else{
  10. echo $path."
    ";
  11. }
  12. }
  13. }
  14. }
  15. $dirname="test"; //Test a directory
  16. showDetail($dirname);
  17. ?>
Copy code

PHP


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