Web Analytics Made Easy -
StatCounter Need help with a php next image script - CodingForum

Announcement

Collapse
No announcement yet.

Need help with a php next image script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help with a php next image script

    Can someone help with a php script that tries to display an image, where the image links to the previous image?

    Example: I have many images in a 'gallery' directory along with other files, such as info.txt, header.jpg, 705.jpg, 704.jpg, 703.jpg, 702.jpg, 701.jpg

    I'd like to create an 'image.php' page that does the following:
    - display the largest jpg (in this case, 705.jpg) from the 'gallery' folder
    - clicking on the image will then reload the page but display the next largest image (in this case, 704.jpg)
    - and so on, as each image is clicked, the next largest image will be displayed.

    I have a similar script that I modified, that displays the largest image, but clicking it just loads the actual image. Not very smart (me or the script!) I'm not sure what would have to be done so that the link could reload the page (with a paramater, perhaps?) that would link to / display the next image in the sequence.

    Any help would be much appreciated, thanks! (I'm also willing to send someone a small paypal fee if they can quickly help.)

    Code:
    <?php
    $images = glob('gallery/*.jpg');
    $images = array_reverse($images);
    for ($i = 0; $i < 1; $i++) {
       echo '<a href="' . $images[$i] . '"><img src="' . $images[$i] . '" alt="" /></a>';
    }
    ?>
    Thanks,
    Chum

  • #2
    I guess I am the only one who has no idea about glob function
    PHP Code:
    <?php
    $images 
    glob('gallery/*.jpg');
    $images array_reverse($images);

    $imageIndex = isset($_REQUEST['index']) ? $_REQUEST['index'] : count($images)-1;
    echo 
    '<a href="?index='.($imageIndex == count($images)-$imageIndex-1).'"><img src="'.$images[$imageIndex].'" alt="" /></a>';
    ?>

    Comment


    • #3
      Thanks much, that works well!

      I did have to make one change to make it show the items in the order I want, which was to remove the following line of code: $images = array_reverse($images);

      Thanks again!
      -Chum

      Originally posted by PHP6 View Post
      I guess I am the only one who has no idea about glob function
      PHP Code:
      <?php
      $images 
      glob('gallery/*.jpg');
      $images array_reverse($images);

      $imageIndex = isset($_REQUEST['index']) ? $_REQUEST['index'] : count($images)-1;
      echo 
      '<a href="?index='.($imageIndex == count($images)-$imageIndex-1).'"><img src="'.$images[$imageIndex].'" alt="" /></a>';
      ?>

      Comment

      Working...
      X