0

我需要为 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>
4

2 回答 2

0

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

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

JUri::root()是您的 Joomla 站点的根目录,因此从那里相应地更改路径到您的图像所在的位置

希望这可以帮助

于 2013-09-13T10:42:51.417 回答
0

这对你有用吗?

<?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>"
?>
于 2013-09-13T11:35:58.627 回答