<tfoot id='Wyu6U'></tfoot>
      <i id='Wyu6U'><tr id='Wyu6U'><dt id='Wyu6U'><q id='Wyu6U'><span id='Wyu6U'><b id='Wyu6U'><form id='Wyu6U'><ins id='Wyu6U'></ins><ul id='Wyu6U'></ul><sub id='Wyu6U'></sub></form><legend id='Wyu6U'></legend><bdo id='Wyu6U'><pre id='Wyu6U'><center id='Wyu6U'></center></pre></bdo></b><th id='Wyu6U'></th></span></q></dt></tr></i><div id='Wyu6U'><tfoot id='Wyu6U'></tfoot><dl id='Wyu6U'><fieldset id='Wyu6U'></fieldset></dl></div>
      <legend id='Wyu6U'><style id='Wyu6U'><dir id='Wyu6U'><q id='Wyu6U'></q></dir></style></legend>
    1. <small id='Wyu6U'></small><noframes id='Wyu6U'>

        <bdo id='Wyu6U'></bdo><ul id='Wyu6U'></ul>
      1. 如何在PHP中显示目录中的文件夹和子文件夹

        时间:2023-07-15
          <bdo id='81suD'></bdo><ul id='81suD'></ul>

          <small id='81suD'></small><noframes id='81suD'>

                <tbody id='81suD'></tbody>
              <legend id='81suD'><style id='81suD'><dir id='81suD'><q id='81suD'></q></dir></style></legend>

                  <i id='81suD'><tr id='81suD'><dt id='81suD'><q id='81suD'><span id='81suD'><b id='81suD'><form id='81suD'><ins id='81suD'></ins><ul id='81suD'></ul><sub id='81suD'></sub></form><legend id='81suD'></legend><bdo id='81suD'><pre id='81suD'><center id='81suD'></center></pre></bdo></b><th id='81suD'></th></span></q></dt></tr></i><div id='81suD'><tfoot id='81suD'></tfoot><dl id='81suD'><fieldset id='81suD'></fieldset></dl></div>

                  <tfoot id='81suD'></tfoot>

                1. 本文介绍了如何在PHP中显示目录中的文件夹和子文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试获取包含文件夹和子文件夹的列表我有以下内容可以让我获取文件夹和子文件夹但我需要像下面这样整理它我一直在尝试但我不知道如何我会绕过.

                  I am trying to get a list with folders and sub folders i have the following that allows me to get the folders and sub folders but i needed it to be sorted out like the e.g below i have been trying but i dont know how i would get around.

                  Root/
                  Root/Images
                  Root/Images/UserImages
                  
                  Root/Text/
                  Root/Text/User1/
                  Root/Text/User1/Folder2
                  

                  但是在monent它的显示是这样的

                  but at the monent its display like this

                  Root/css/
                  tree/css/
                  js/
                  images/
                  

                  PHP 代码:

                      function ListFolder($path)
                  {
                  
                      $dir_handle = @opendir($path) or die("Unable to open $path");
                  
                      //Leave only the lastest folder name
                      $dirname = end(explode("/", $path));
                  
                      //display the target folder.
                      echo ("$dirname/");
                      while (false !== ($file = readdir($dir_handle)))
                      {
                          if($file!="." && $file!="..")
                          {
                              if (is_dir($path."/".$file))
                              {
                                  //Display a list of sub folders.
                                  ListFolder($path."/".$file);
                                  echo "<br>";
                              }
                          }
                      }
                  
                  
                      //closing the directory
                      closedir($dir_handle);
                  }
                  
                      ListFolder("../");
                  

                  谢谢

                  推荐答案

                  将目录名收集到一个数组中,而不是直接echo.在数组上使用 sortforeach 循环来打印列表.

                  Collect the directory names in an array instead of echoing them directly. Use sort on the array and a foreach-loop to print the list.

                  所以代替 echo ("$dirname/"); 你会使用 $dirnames[] = $dirname; (使 $dirnames 全局并在你之前初始化它第一次调用ListFolder").然后在递归运行ListFolder"之后,您将执行 sort($dirnames); 然后像这样的输出:

                  So instead of echo ("$dirname/"); you would use $dirnames[] = $dirname; (make $dirnames global and initialize it before your first call of "ListFolder"). Then after the recursive run of "ListFolder", you'd execute sort($dirnames); and then something like this for the output:

                  foreach ($dirnames as $dirname)
                  {
                    echo $dirname . '<br />';
                  }
                  

                  这篇关于如何在PHP中显示目录中的文件夹和子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 PHP 删除空子文件夹 下一篇:在 Windows 上列出包含 Unicode 字符的目录

                  相关文章

                2. <small id='b3D4u'></small><noframes id='b3D4u'>

                  <i id='b3D4u'><tr id='b3D4u'><dt id='b3D4u'><q id='b3D4u'><span id='b3D4u'><b id='b3D4u'><form id='b3D4u'><ins id='b3D4u'></ins><ul id='b3D4u'></ul><sub id='b3D4u'></sub></form><legend id='b3D4u'></legend><bdo id='b3D4u'><pre id='b3D4u'><center id='b3D4u'></center></pre></bdo></b><th id='b3D4u'></th></span></q></dt></tr></i><div id='b3D4u'><tfoot id='b3D4u'></tfoot><dl id='b3D4u'><fieldset id='b3D4u'></fieldset></dl></div>

                    • <bdo id='b3D4u'></bdo><ul id='b3D4u'></ul>
                    <legend id='b3D4u'><style id='b3D4u'><dir id='b3D4u'><q id='b3D4u'></q></dir></style></legend>

                      <tfoot id='b3D4u'></tfoot>