【问题标题】:How to read in all the images in a file and output them as image form on the website?如何读取文件中的所有图像并将它们作为图像形式输出到网站上?
【发布时间】:2016-09-17 02:48:00
【问题描述】:

所以在我的文件夹 (x) 中,有 HTML 文件和我的图像的另一个文件夹 (y)。我想读取文件夹 y 中的所有图像并将它们作为<img> 形式输出到我的 HTML 页面上。我查找了 php 和 javascript,试图让它们工作,但没有好运。有人可以帮我吗?

假设文件夹 y 中的所有图像都是 .jpg 格式。

【问题讨论】:

    标签: php html


    【解决方案1】:

    这只是获取与通配符匹配的所有文件的目录列表的问题。在您的情况下,*.jpg。 为此,您可以使用 glob 函数,然后使用 forEach 循环遍历匹配的文件名列表。

    <?php
    // Creates a page full of jpg images found in the specified directory (current one if none specified)
    function showFiles($findMe)
    {
        foreach (glob($findMe) as $filename) 
                echo "<img src='$filename'/>";
    }
    showFiles("*.jpg");
    ?> 
    

    【讨论】:

      猜你喜欢
      • 2021-11-10
      • 2021-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-17
      • 2023-03-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多