Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php浏览多个目录_Php - Fatal编程技术网

Php浏览多个目录

Php浏览多个目录,php,Php,使用上一篇关于显示目录的帖子中的代码 <?php $files = array(); $dir = opendir('races/ob/'); // open the cwd..also do an err check. while(false != ($file = readdir($dir))) { if(($file != ".") and ($file != "..") and ($file != "index.

使用上一篇关于显示目录的帖子中的代码

<?php 

      $files = array();
      $dir = opendir('races/ob/'); // open the cwd..also do an err check.

      while(false != ($file = readdir($dir))) {
              if(($file != ".") and ($file != "..") and ($file != "index.php")) {
                      $files[] = $file; // put in array.
              }   
      }

      natsort($files); // sort.

      // print.
      foreach($files as $file) {
              echo("<span class='txt-spacing'><a href='$file'>$file</a> <br />\n</>");
    }
?>
函数scandir\u递归($path)
{
如果($result=scandir($path))
{
$scan=$result=array_-filter($result,function($a){return!在_-array($a,['.','..,','index.php']);});
foreach($scan as$sub)
if(is_dir($subdir=“$path/$sub”))
如果($dir=scandir\u recursive($subdir))
$result=array_merge($result,array_map(函数($a)use($sub){return“$sub/$a”;},$dir));
}
返回$result;
}
$files=scandir_递归('races/ob');
natsort($文件);
foreach($files作为$file)
回声(“
\n”);
目前,您的代码不会递归地迭代文件夹结构。它将只扫描
races/ob/
目录。这就是你想要的吗?是的,我希望它只扫描比赛/ob/我有另一个div设置,另一个部分是yb(用于鸽子赛跑者和统计:D)。目前它显示俱乐部的所有文件夹名称,但我无法点击该文件夹并在新页面上加载txt文件;/例如,如果这有助于你的想法你考虑过使用数据库吗?@PeeHaa我真的很想使用数据库,但他们认为编写代码来处理通过电子邮件提交的比赛结果的人编写了rebol,然后程序将其转换为.txt,这是一个大混乱的时刻,也许一旦我获得了一点关于php的更多知识,我可以重新编写脚本:)代码是一次列出一切,而不是一旦我点击一个俱乐部名称,然后进入俱乐部文件夹生成文件列表,我如何修改它来做到这一点?希望我的问题足够清楚。谢谢,我只是在$file()之前添加了路径
     Races
        |
       OldBird
            |
          Clubs Name Listing
              |
            List all .txt files for users to view
function scandir_recursive($path)
{
    if ($result = scandir($path))
    {
        $scan = $result = array_filter($result, function ($a) { return !in_array($a, ['.', '..', 'index.php']); });
        foreach ($scan as $sub)
            if (is_dir($subdir = "$path/$sub"))
                if ($dir = scandir_recursive($subdir))
                    $result = array_merge($result, array_map(function ($a) use ($sub) { return "$sub/$a"; }, $dir));
    }
    return $result;
}

$files = scandir_recursive('races/ob');
natsort($files);
foreach ($files as $file)
    echo("<a class='txt-spacing' href='$file'>$file</a><br>\n");