Show an image on a specific date

Hi I need to setup a section of a website titled "on this day " I need to show certain images depending on the date and only have them show for that day then be removed. Is this possible with PHP? if so how would I go about sorting it?
Sorry new to the php side of things.


Based on the little information you provided: “it depends.”

I think perhaps the most straightforward way is to save the images in 31 folders numbered 1 to 31 and add pictures that correspond to each day in them. ideally, you would want to keep a consistent file naming convention when it comes to dates. For example: image_nnn_YYYY-mm-dd.png

In PHP, you could do something like this (not tested):

$today = date('j'); // the day value without leading zeros. See [PHP date formats](

$path = '/your/path/to/images/folders/';

$files_array = glob(realpath($path . $today) . '/*.*'); // creates an array with the filenames in the given folder

$random_file = array_rand($files_array); // pick a random file. 

$random_image = $files_array[$random_file];

$image_date = substr($random_image, -14, 10); // will give you the date of the image file

$on_this_day_caption = 'On this day, ' . date('F jS, Y', strtotime($image_date)) . '...';

Now you should have something to work with your html file:

<img src="<?= $path . $image_file ?>" alt="<?= $on_this_day_caption ?>">

Although I am not sure what you mean by “then be removed”, I hope this will help you get started.

Good luck!

Hi wal517 thanks for responding.
I will give that a try. Really what I am trying to do is have a web page with a section that will show a picture and a short paragraph on a set date then remove it after 1 day. The section is for a memorial of members who have passed. The picture and text would automatically show on that specific date then be removed allowing for another to replace it on their specific date. If nothing needs showing on a date then a short message would show i.e. " nothing for this date"
Hope this makes it clear what I am trying to achieve.


Sponsor our Newsletter | Privacy Policy | Terms of Service