dousu5608 2012-12-06 07:13
浏览 80
已采纳

从/ images中的多个文件夹中获取图像,并将每个文件夹内容放在其自己的div中

I am trying to make php do the following.

I have a structure of folders in my root directory. /images/1234, /images/2345, /images/3456 etc. (multiple folders all in images)

I would like to get the contents of each folder and put their contents into their own div, using php and not hard coding as the folders and files will change regularly.

<div><img src="images/1234/1.jpg"><img src="images/1234/2.jpg"><img src="images/1234/3.jpg"></div>
<div><img src="images/2345/1.jpg"><img src="images/2345/2.jpg"><img src="images/2345/3.jpg"></div>
<div><img src="images/3456/1.jpg"><img src="images/3456/2.jpg"><img src="images/3456/3.jpg"></div>

The files/folders will constantly be added so these divs would have to be in some sort of foreach loop for each folder found in the images directory.

Essentially each folder in images folder would be a div, the divs would auto populate as the browser was refreshed if new folder existed.

I can make it work with php to bring out all images and just place on page,r but I need this structure instead. Thanks for any help.

  • 写回答

2条回答 默认 最新

  • drmet46444 2012-12-06 07:42
    关注
    foreach (glob('images/*') as $dir) {
      echo '<div>'; // One div per directory
      foreach (glob($dir."/*.jpg") as $img) {
        echo "<img src='$img'/>";
      }
      echo "</div>
    ";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式
  • ¥50 potsgresql15备份问题
  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错