mordie — 2013-01-18T15:08:56-05:00 — #1
Is there a PHP photo-of-the-day script that can:
- show one image per day (changing at, say, midnight server-time)?
- rotate through 365 images in order (for example, 01.png, 02.png, . . . 365.png)?
- and then start again every year from the first image?
I was informed by a consultant that PHP cannot do this and that I'd have to convert my site to ASP.
Is this correct?
guido2004 — 2013-01-18T15:25:32-05:00 — #2
No that's not correct.
If you name your images 1.png to 365.png and you save them in the same folder as the script, then this line of php code should do what you want:
echo '<img src="' . (date('z') + 1) . '.png" >';
Actually you should have 366 images, otherwise once every 4 years you're 1 image short
cups — 2013-01-18T15:32:05-05:00 — #3
Essentially it is as easy as:
$dayofyear = date('z');
// test it
echo 'Today is day number ' . $dayofyear ;
<img src="/images/<?php echo $dayofyear ?>.jpg" />
Today is day number 17
<img src="/images/17.jpg" />
Now, when it becomes slightly trickier is when:
The images are not all .jpg
The images are different sizes and you want to tell the browser height= width=
The images are different sizes and you want to resise them
You want meaningful alt texts to accompany each image
But if its just a 366 day image rotator you want ... it really is that simple.
mordie — 2013-01-19T23:19:44-05:00 — #4
Cups' code does the job well.
cups — 2013-01-20T07:32:34-05:00 — #5
@guido2004; 's code would have done just as well, and he avoids you having to have a 0.jpg file for day number one.
If none of the other provisos that I listed apply in your case, then I am happy for you.
Thanks for replying.