display image with newest date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Verboten
Forum Newbie
Posts: 3
Joined: Mon Oct 07, 2002 4:33 am

display image with newest date

Post by Verboten »

Hey there
I run a gallery site, and on the main index.html of my site I need a script to display the image with the newest date, pulled from a specified directory (where all images from the gallery are stored). Basically showing everyone the last image that has been uploaded and attract users into the gallery. Anyone know where I would start with this? I could also pull the image based on the highest alphabetized name, since the gallery program renames all files in alpha order (ie: aa.jpg, ab.jpg, ac.jpg etc).

Using the filenames seems to be the more reliable way in case i have to alter an image and then reupload it, I wouldnt want it to show on the main page again just because the date had changed by me messin with the pic.
My site is ran on Unix, and php 4.22

I couldnt find anything in the manual or in the archives of this forums.
Thanks for any help or hints
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You should have a look at the filesystem functions and specifically the filemtime() function. The directory functions will be useful too.

Mac
Verboten
Forum Newbie
Posts: 3
Joined: Mon Oct 07, 2002 4:33 am

Post by Verboten »

hmm correct me if im wrong but wouldnt those functions you linked me to, only help me display what the date of the newest file was, and not display the file itself? I dunno im not really sure what the best route to go is.
Thanks
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

These functions will help you go through a folder and pick out images based on certain criteria (eg. which image was last updated). Of course they won't display the images for you but you will have the image's name that you want to display. To display the file you just need to put that image's name into the IMG tag in HTML:

Code: Select all

echo '<img src="'.$latest_image.'" alt="The last image that was updated" />';
Mac
Post Reply