Page 1 of 1

To load image conditionally

Posted: Sat Jan 24, 2004 1:25 am
by pirolilla
I need aid with another one script PHP.

In a page an image is due to open (the cover of a newspaper) that the website who lodges it changes every day. The name of the image contains reference to the date of every day, but the image is incorporated last hours of the new day, with which the first hours of every day the new image not yet exists.

I use script PHP so that it changes the name of the image in agreement with the date, but need that the new image was not loaded until this one exists in that website. Script that I need would have east scheme:

If imagendate24.gif exists load imagendate24.gif, if imagendate24.gif does not exist load imagendate23.gif

Understanding that date24 makes reference to the present day and date23 to the previous day.

In my script PHP I have loaded a variable, that is:

$datemonth = date(d);

and it would create another one, that would be:

$datemonth = date(d) -1;

Thanks for your aid.

Posted: Sat Jan 24, 2004 3:23 am
by microthick
Your code might look like this.

Code: Select all

<?php
$day = date(d);
while (!file_exists("someimage".$day.".jpg")) {
     // Keep looping til a picture is available
     // In the loop decrement the $day until we find a day that has a picture.
     $day--;
}

// If we're out of the loop, then there is a picture for the last $day.
$validpicture = "someimage".$day.".jpg";
?>
This has not been tested at all.

Posted: Sat Jan 24, 2004 3:38 am
by pirolilla
I will try this. Thanks.