我需要为Joomla构建一个动态图库插件!将进入特定文件夹并从文件夹中提取所有图像,并将其中的第一个显示为大型预览图像,其余部分显示在列表中。之后我需要在灯箱中打开预览图像,如果点击,在灯箱中我需要有所列图像的小缩略图。
但是知道我只需要php去文件夹并从指定的文件夹中取出所有图像。我已经google了一下,找到了一些解决方案,但由于某些原因我不明白这种方法不起作用。有人可以告诉我,代码有什么问题吗?
谢谢!
<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>
答案 0 :(得分:0)
我认为这是因为你没有正确定义路径。请尝试使用以下内容:
$images_dir = JUri::root() . 'plugins/content/plg_new/images';
JUri::root()
是您Joomla网站的根目录,因此请相应地将路径更改为图片的位置
希望这有帮助
答案 1 :(得分: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>"
?>