PHP Photo-of-the-Day-Per-Day-Every-Year script

Is there a PHP photo-of-the-day script that can:

  1. show one image per day (changing at, say, midnight server-time)?
  2. rotate through 365 images in order (for example, 01.png, 02.png, . . . 365.png)?
  3. 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?

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:


<?php
  echo '<img src="' . (date('z') + 1) . '.png" >';
?>

Actually you should have 366 images, otherwise once every 4 years you’re 1 image short :wink:

Essentially it is as easy as:


<?php
$dayofyear = date('z');

// test it
echo 'Today is day number ' . $dayofyear ;
?>

<img src="/images/<?php echo $dayofyear ?>.jpg" />

Gives:
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.

Thanks, Gentlemen.

Cups’ code does the job well.

Much appreciated.

@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.