【问题标题】:Place images from a folder into list with preview将文件夹中的图像放入带有预览的列表中
【发布时间】:2013-09-13 10:38:29
【问题描述】:

我需要为 Joomla 构建一个动态图片库插件!这将进入特定文件夹并从文件夹中提取所有图像,并将其中的第一个显示为大预览图像,其余显示在列表中。之后,如果单击,我将需要在灯箱中打开预览图像,并且在灯箱中我还需要列出图像的小缩略图。

但知道我只需要 php 即可转到文件夹并从指定的文件夹中提取所有图像。我用谷歌搜索了一下,找到了一些解决方案,但是由于某种我不明白的原因,这不起作用。谁能告诉我,代码有什么问题?

谢谢!

<div id="images">
        <?php 
        $images_dir = 'images/';
        $scan = scandir($images_dir);
        echo '<img src="' . $images_dir . $scan[2] . '"alt="image" />';
        ?>
        <ul id="smallimages">
        <?php
        for($i=0; $i<count($scan); $i++){
            $ext = substr($scan[$i], strpos($scan[$i], '.'), strlen($scan[$i]-1));
        $filetypes = array('.jpg', '.JPEG', '.jpeg');
        if(in_array($ext, $filetypes)){
            echo '<li><a href="' . $images_dir . $scan[$i] . '"><img src="' . $images_dir . $scan[$i] . '" alt="' . $scan[$i] . '"></a></li>';}         }?></ul>

</div>

【问题讨论】:

    标签: php image joomla gallery photo-gallery


    【解决方案1】:

    我认为这是因为您没有正确定义路径。尝试使用以下内容:

    $images_dir = JUri::root() . 'plugins/content/plg_new/images';
    

    JUri::root() 是您的 Joomla 站点的根目录,因此请根据您的图像所在位置更改从那里开始的路径

    希望对你有帮助

    【讨论】:

      【解决方案2】:

      这对你有用吗?

      <?php
      $image_directory="hrevert/images/";
      $pictures = glob("$image_directory*.{gif,jpg,png}", GLOB_BRACE); 
      
      //displays the first image
      $first_img=reset($pictures);
      echo "<img src=\"".$first_img."\" width='20px' />"; 
      
      
      //loops through other images and prints them
      echo "<ul>";
      foreach($pictures as $picture)  {
      
          echo "<a href='$picture'><img src=\"".$picture."\" width='20px' /></a>"; 
      }
      echo "</ul>"
      ?>
      

      【讨论】:

        猜你喜欢
        • 2016-12-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-17
        • 1970-01-01
        • 1970-01-01
        • 2013-09-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多