Foreach loop for fotorama


Foreach loop for fotorama

我试图使用foreach循环插件fotorama。

我想做的是加载一个一半大小的图像为主要的画廊图像。我在一个foreach工作,但我想使用一个完整的图像的数据全标签,但我不能让它工作。

工作代码

<div class="fotorama"
                 data-allowfullscreen="native"
                 data-nav="thumbs"
                 data-fit="scaledown"
                 data-width="100%"
                 data-height="100%"
                 data-arrows="true"
                 data-click="true"
                 data-swipe="true">
                <?php
                      $dirname = "admin/image-upload/uploads/";
                      $images = glob($dirname."*.*");
                      foreach($images as $image) {
                      echo '<img src="'.$image.'" /><br />';
                      }
                ?>
            </div>

这就是我想做的。

<div class="fotorama"
                 data-allowfullscreen="native"
                 data-nav="thumbs"
                 data-fit="scaledown"
                 data-width="100%"
                 data-height="100%"
                 data-arrows="true"
                 data-click="true"
                 data-swipe="true">
                <?php
                      $dirname = "admin/image-upload/uploads/";
                      $images = glob($dirname."*.*");
                      $dirname2 = "admin/image-upload/full/";
                      $images2 = glob($dirname2."*.*");
                      $fullImgs = "<img data-full=".$image2." src=".$image." /><br />";
                      foreach($fullImgs as $fullImg) {
                      echo $fullImg;
                      }
                ?>

            </div>

thanks in advanced guys

试试这个:

$dirname = "admin/image-upload/uploads/";
$images = glob($dirname."*.*");
$dirname2 = "admin/image-upload/full/";
$images2 = glob($dirname2."*.*");
$array = array_merge($images, $images2);
// Supossing both array have same length
$length = count($images);
for($i = 0; $j = $length; $i < $length; $i++, $j++) {
    echo '<img data-full=".$images2[$j]." src=".$images[$i]." /><br />';
}

我想你想要的是:

<?php
  $dirname = "admin/image-upload/uploads/";
  $images = glob($dirname."*.*");
  $dirname2 = "admin/image-upload/full/";
  $images2 = glob($dirname2."*.*");
  //assuming $images and $images2 are the same length...
  foreach ($images as $k => $v) {
    echo "<img data-full=".$images2[$k]." src=".$v." /><br />";
  }
?>

还没有测试过,但应该给出一个想法…

您的代码不会像这样工作。如果我理解正确的话,你在两个不同的目录中有大小格式的相同图像。要将它们作为一对显示,您需要在这两个文件之间建立连接-因为您的脚本如何知道哪些图像属于一起?您可以使用数据库,但在您的情况下,我认为在文件名中建立连接更容易。例如,将目录中的图片命名为小图像

Image_7263.pngImage_0172.png

以此类推。对于大图像,您只需在名称后面附加_BIG。

然后使用foreach循环在目录中循环查找小图像。对于其中的每个图像,您将_BIG附加到文件名的末尾,并将其包含在大图像的目录中。

$smallImages = glob ("/path/to/small/images/*.*");
foreach ($smallImages as $img)
{
$name = substr ($img, 0, strlen ($img)-4); //Remove the .png or .jpg
$bigImg = "/path/to/big/images/".name."_BIG.jpg"; // or whatever image type you are using
echo "<img data-full='"".$bigImg."'" src='"".$img."'" />
}