Jump to content

Recommended Posts

Hello, I am a little stuck trying to write a script that displays the newest 3 images within a 'thumbnails' folder on the home page of my website. All the thumbnail images in the folder are listed sequentially, so by newest 3 images, they could be 156.jpg, 155.jpg, and 154.jpg.

 

Then when I later upload image 157, the script would display image thumbnails 157, 156, and 155 on the home page.

 

I'm only concerned with linking the thumbnails to a single '/gallery' folder, they don't need to individually link to different places.

 

Anybody care to assist with helping to code this?

Link to comment
https://forums.phpfreaks.com/topic/133653-php-script-to-display-newest-3-images/
Share on other sites

I'd probably try looping through every folder images are in > saving the path and file name in an array > sorting the array by the file name > selecting top 3.. first idea that came to mind.

 

I don't think people will just create this little app for you, try working on an idea then coming back when you have some code and get stuck or run into problems...

 

Adam

All the images are in a single folder. So the script would likely just have to see what the three largest numbered images are and then display them on a page. I'm new to php so this is pretty confusing to me. :( Any help would be appreciated!

ok well if you need it in the future pm.  from a personal point of view i think it would be easier that way then you could upload new images no matter where you are and it will alay be displaying the latest images on the page.

If the images are named between 100 and 999, you can do a simple sort on the paths returned by e.g. glob(). Actually, I believe glob() automatically sorts the paths (ascending).

 

<?php
$images = glob('/path/to/images/*.jpg');
$images = array_reverse($images);
for ($i = 0; $i < 3; $i++) {
   echo '<img src="' . $images[$i] . '" alt="" /><br />';
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.