<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中显示目录中的文件夹和子文件夹

        how to display folders and sub folders from dir in PHP(如何在PHP中显示目录中的文件夹和子文件夹)
          <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中显示目录中的文件夹和子文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                  PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                  mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                  Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                  Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                  Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)

                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>
                              <tbody id='b3D4u'></tbody>