<legend id='TG6J1'><style id='TG6J1'><dir id='TG6J1'><q id='TG6J1'></q></dir></style></legend>

      <small id='TG6J1'></small><noframes id='TG6J1'>

    1. <i id='TG6J1'><tr id='TG6J1'><dt id='TG6J1'><q id='TG6J1'><span id='TG6J1'><b id='TG6J1'><form id='TG6J1'><ins id='TG6J1'></ins><ul id='TG6J1'></ul><sub id='TG6J1'></sub></form><legend id='TG6J1'></legend><bdo id='TG6J1'><pre id='TG6J1'><center id='TG6J1'></center></pre></bdo></b><th id='TG6J1'></th></span></q></dt></tr></i><div id='TG6J1'><tfoot id='TG6J1'></tfoot><dl id='TG6J1'><fieldset id='TG6J1'></fieldset></dl></div>
      <tfoot id='TG6J1'></tfoot>
        <bdo id='TG6J1'></bdo><ul id='TG6J1'></ul>
      1. 使用 php RecursiveDirectoryIterator 构建一个简单的目录浏览器

        时间:2023-07-15

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

            1. <small id='5gHNm'></small><noframes id='5gHNm'>

              <tfoot id='5gHNm'></tfoot>
            2. <legend id='5gHNm'><style id='5gHNm'><dir id='5gHNm'><q id='5gHNm'></q></dir></style></legend>
                  <bdo id='5gHNm'></bdo><ul id='5gHNm'></ul>
                    <tbody id='5gHNm'></tbody>
                  本文介绍了使用 php RecursiveDirectoryIterator 构建一个简单的目录浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  嗨我正在尝试构建简单的目录浏览器以使用 php RecursiveDirectoryIterator 浏览文件夹和子文件夹..我需要有关如何创建它的帮助.我已经开始使用以下代码.

                  Hi i am trying to build simple directory browser to browse folders and sub-folders uing php RecursiveDirectoryIterator .. i need help of how to create this. i have started with the following code.

                  $dir = dirname(__FILE__); //path of the directory to read
                  $iterator = new RecursiveDirectoryIterator($dir);
                  foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::CHILD_FIRST) as  $file) {
                  if (!$file->isFile()) { //create hyperlink if this is a folder
                  echo "<a href=". $file->getPath().">" . $file->getFilename() . "</a>";
                  }else{ //do not link if this is a file
                    $file->getFilename()
                    }
                  }
                  

                  推荐答案

                  请允许我为您编写代码....

                  Allow me to code that for you....

                  <?php
                  $root = __DIR__;
                  
                  function is_in_dir($file, $directory, $recursive = true, $limit = 1000) {
                      $directory = realpath($directory);
                      $parent = realpath($file);
                      $i = 0;
                      while ($parent) {
                          if ($directory == $parent) return true;
                          if ($parent == dirname($parent) || !$recursive) break;
                          $parent = dirname($parent);
                      }
                      return false;
                  }
                  
                  $path = null;
                  if (isset($_GET['file'])) {
                      $path = $_GET['file'];
                      if (!is_in_dir($_GET['file'], $root)) {
                          $path = null;
                      } else {
                          $path = '/'.$path;
                      }
                  }
                  
                  if (is_file($root.$path)) {
                      readfile($root.$path);
                      return;
                  }
                  
                  if ($path) echo '<a href="?file='.urlencode(substr(dirname($root.$path), strlen($root) + 1)).'">..</a><br />';
                  foreach (glob($root.$path.'/*') as $file) {
                      $file = realpath($file);
                      $link = substr($file, strlen($root) + 1);
                      echo '<a href="?file='.urlencode($link).'">'.basename($file).'</a><br />';
                  }
                  

                  这篇关于使用 php RecursiveDirectoryIterator 构建一个简单的目录浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:php从目录中生成随机图像 下一篇:使用php扫描目录和子目录中的文件并将其路径存储在数组中

                  相关文章

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

                    1. <legend id='21aFv'><style id='21aFv'><dir id='21aFv'><q id='21aFv'></q></dir></style></legend>

                      <small id='21aFv'></small><noframes id='21aFv'>

                      • <bdo id='21aFv'></bdo><ul id='21aFv'></ul>
                    2. <tfoot id='21aFv'></tfoot>