dongwen1871 2016-10-12 08:53
浏览 40
已采纳

如何从所有子目录中获取图像名称?

I have used following php code to get all images names from relevant directory.

$dir = "images";
$images = scandir($dir);
$listImages=array();
foreach($images as $image){
    $listImages=$image;
    echo ($listImages) ."<br>";
}

This one works perfectly. But I want to get all images file names within all sub directories from relevant directory. Parent directory does not contain images and all the images contain in sub folders as folows.

  • Parent Dir
    • Sub Dir
      • image1
      • image2
    • Sub Dir2
      • image3
      • image4

How I go through the all sub folders and get the images names?

  • 写回答

2条回答 默认 最新

  • dtkf64283 2016-10-12 09:28
    关注

    Try following. To get full directory path, merge with parent directory.

    $path = 'images'; // '.' for current
       foreach (new DirectoryIterator($path) as $file) {
       if ($file->isDot()) continue;
    
       if ($file->isDir()) {
           $dir = $path.'/'. $file->getFilename();
    
       $images = scandir($dir);
           $listImages=array();
           foreach($images as $image){
               $listImages=$image;
               echo ($listImages) ."<br>";
           }
       }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 java corba的客户端该如何指定使用本地某个固定IP去连接服务端?
  • ¥15 activiti工作流问题,求解答
  • ¥15 有人写过RPA后台管理系统么?
  • ¥15 Bioage计算生物学年龄
  • ¥20 如何将FPGA Alveo U50恢复原来出厂设置哇?
  • ¥50 cocos2d-x lua 在mac上接入lua protobuf?
  • ¥15 es 7.17.20版本生成时间戳
  • ¥15 wpf dategrid表头排序图标自定义
  • ¥15 xshell无法连接提示ssh服务器拒绝密码
  • ¥15 AT89C52单片机C语言关于串口通信的位操作