php顯示當前文件所在的文件以及文件夾所有文件,樹形展開

  1. <?php
  2. $path = “./”;
  3. function createDir($path = ‘.’)
  4. {
  5. if ($handle = opendir($path))
  6. {
  7. echo “
      “;

    • while (false !== ($file = readdir($handle)))
    • {
    • if (is_dir($path.$file) && $file != ‘.’ && $file !=’..’)
    • printSubDir($file, $path, $queue);
    • else if ($file != ‘.’ && $file !=’..’)
    • $queue[] = $file;
    • }
    • printQueue($queue, $path);
    • echo “

    “;

  8. }
  9. }
  10. function printQueue($queue, $path)
  11. {
  12. foreach ($queue as $file)
  13. {
  14. printFile($file, $path);
  15. }
  16. }
  17. function printFile($file, $path)
  18. {
  19. echo “
  20. $file
  21. “;

  22. }
  23. function printSubDir($dir, $path)
  24. {
  25. echo “
  26. $dir”;
  27. createDir($path.$dir.”/”);
  28. echo “
  29. “;

  30. }
  31. createDir($path);
  32. ?>
  33. 原文地址:https://www.freejs.net/article_jquerywenzi_112.html

You May Also Like