How to display different image each day of the week with php

Post Reply
User avatar
Saman
Lieutenant Colonel
Lieutenant Colonel
Posts: 828
Joined: Fri Jul 31, 2009 10:32 pm
Location: Mount Lavinia

How to display different image each day of the week with php

Post by Saman » Fri Jul 15, 2011 6:20 pm

This PHP script will get the day of the week from the server date and then display an image (jpg or gif) to match.

Code: Select all

<?php 

/** 
 * Change the name of the image folder 
 * 
 * Images must be named Monday.gif, Tuesday.gif etc 
 */ 

// Change to the location of the folder containing the images 
$image_folder = "images/days"; 

// You do not need to edit below this line 

$today = date('l'); 

if (file_exists($image_folder."/".$today.".gif")) { 
  echo "<img src=\"$image_folder/".$today.".gif\">"; 
} 
else { 
  echo "No image was found for $today"; 
} 

?>
Post Reply

Return to “PHP & MySQL”