Php 将文件夹中的图像放入带有预览的列表中

Php 将文件夹中的图像放入带有预览的列表中,php,image,joomla,gallery,photo-gallery,Php,Image,Joomla,Gallery,Photo Gallery,我需要建立一个动态图像库插件Joomla!这将进入一个特定的文件夹,并从文件夹中取出所有图像,并将其中的第一个图像显示为大预览图像,其余图像显示在列表中。之后,如果单击,我需要在lightbox中打开预览图像,在lightbox中,我还需要列出图像的小缩略图 但是我知道我只需要php就可以转到该文件夹并从指定的文件夹中取出所有图像。我在谷歌上搜索了一下,找到了一些解决方案,但由于我不明白的原因,这不起作用。有人能告诉我,代码有什么问题吗 谢谢 <div id="images">

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

但是我知道我只需要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>


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

$images_dir = JUri::root() . 'plugins/content/plg_new/images';
JUri::root()
是Joomla站点的根,因此请根据图像所在的位置相应地更改路径


希望这有帮助这对你有用吗

<?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>"
?>