Hi there,
Wondering if you might be able to give me a hand.
I’m putting together a website that has a splash page, and the splash page is to have a set image for every month of the year - one that automatically changes.
Anyone know how this might be achieved?
Many thanks in advanced.
Fergus
<?php
$totalPics="7"; // Total photos in folder
$photoOfTheDay = Array ( // Add up to 31 photos below
'1' => '../boutique_images/image1.jpg' , // Name of or Path to image
'2' => '../boutique_images/image2.jpg' , // Name of or Path to image
'3' => '../boutique_images/image3.jpg' , // Name of or Path to image
'4' => '../boutique_images/image4.jpg' , // Name of or Path to image
'5' => '../boutique_images/image5.jpg' , // Name of or Path to image
'6' => '../boutique_images/image6.jpg' , // Name of or Path to image
'7' => '../boutique_images/image7.jpg' , // Name of or Path to image
);
// published at: scripts.tropicalpcsolutions.com
// Place day of month in variable 'x'
//$x=date("d");
// A website vistor made a suggestion to change the date function to use j
// instead of d. This causes the date to be read without leading zeros. I have used n as it relates to month rather than day
$x=date("n"); //Thanks for the suggestion Andrew
// If value of date exceeds the amount of photos then pick a random photo to display
if($x > $totalPics) { $x=rand(1,$totalPics); }
// Display image
echo <<<EOC
<center><img src="$photoOfTheDay[$x]"></center>
EOC;
?>
Here’s a script that gets the content of the folder of images and
shows the one for the current month. All you have to do is put 12
pictures in a folder on your server (with an FTP app) and the script
does all the rest. You could modify this to be one per day if you
prefer.
On Jan 28, 2011, at 9:31 PM, DeltaDave wrote:
And here is a simple one in action - if you look at the source code
you will see that image1.jpg is being displayed.
Here’s a script that gets the content of the folder of images >and shows the one for the current month. All you have to do >is put 12 pictures in a folder on your server (with an FTP >app) and the script does all the rest. You could modify this >to be one per day if you prefer.
A silly question, I know, but what am I supposed to call the files? have tried everything and doesn’t seem to work…
It shouldn’t matter what you call them – they have to be images,
naturally, but any 12 images will work. If you want to have a
particular image for each month, then just name them so they sort into
month order when placed in a directory. They will be listed in
alphabetical order, so something like aaa_january.jpeg,
bbb_february.jpeg, ccc_march.jpeg, etc…
You need to have PHP5 on your server, and you need to change the
filename of your Web page from whatever.html to whatever.php.
And I had to add one more line to the script. I didn’t sort the photos
after stripping out any hidden files, so they started at the index 2
rather than 0. Sort re-indexes the array, bringing its lowest index
back to 0. I updated the Gist, so it should be correct now.
Walter
On Jan 29, 2011, at 10:31 AM, Fergus T wrote:
Here’s a script that gets the content of the folder of images >and
shows the one for the current month. All you have to do >is put 12
pictures in a folder on your server (with an FTP >app) and the
script does all the rest. You could modify this >to be one per day
if you prefer.
A silly question, I know, but what am I supposed to call the files?
have tried everything and doesn’t seem to work…