Search code examples
phparraysforeachdirectoryglob

Link small images to big images


I would like to make a gallery. I have to folder, one with small images for the thumbnails and one with big images for the lightbox. I would like to link the thumbnails to the big images. How do I do that. I found following script and I pasted a script I would like to have it look like (the problem is it doesn't work like that).

I usually don't code with PHP thats why I ask, I guess theres a way to save the links in an array.

The PHP I found

<?php 
  foreach(glob('./images/small/*.*') as $file_small){
    echo "<img src='".$file_small."' />";
  }
?>

The PHP I would like

 <?php 
      foreach(glob('./images/small/*.*') as $file_small and glob('./images/big/*.*') as $file_big){
        echo "<a href='".$file_big."'><img src='".$file_small."' /></a>";
      }
    ?>

Solution

  • Use phpThumb http://phpthumb.sourceforge.net/ for generating thumbnails and use the php code like this :

    <?php 
      foreach(glob('./images/big/*.*') as $file_big){
        echo "<a href='".$file_big."'><img src='phpThumb/phpThumb.php?src=../".$file_big."' /></a>";
      }
    ?>