SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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?

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,494
    Mentioned
    161 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by Mordie View Post
    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 Code:
    <?php
      
    echo '<img src="' . (date('z') + 1) . '.png" >';
    ?>
    Actually you should have 366 images, otherwise once every 4 years you're 1 image short

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Essentially it is as easy as:

    PHP Code:
    <?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.

  4. #4
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Gentlemen.

    Cups' code does the job well.

    Much appreciated.

  5. #5
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    @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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •