View Full Version : To load image conditionally

01-24-2004, 08:20 AM
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.

01-27-2004, 02:02 PM
not tried this yet.

Note, check out your date(d) command that you have used. this will cause problems when it is the 1st day of the month as date-1 = 0 is not valid.

$date_today = date(d);
$date_yest = date(d) - 1;

$filename = "imagen".$date_today.".gif";
$filename1 = "imagen".$date_yest.".gif";

if (file_exists($filename))
print('<img src="'.$filename.'">');
} else {
print('<img src="'.$filename1.'">');

01-27-2004, 05:42 PM
The script is fine, but i have a problem. I don't know solve this problem of annotation:

The name of original image file is this:


The numbers correspond with the days of the month, the month and the year, corresponding with these variables:

$dial = date(d) ;
$diala = date(d) -1 ;
$mesl = date(m) ;
$anol = date(Y) ;

Then, to create the variables of the today image and the one of yesterday, I have a problem:

$filename = "http://www.elpais.es/diario/media/$anol$mesl/$diac/opinion/vinetas/$anol$mesl$dialimageCO.gif";

$filename1 = "http://www.elpais.es/diario/media/$anol$mesl/$diac/opinion/vinetas/$anol$mesl$dialaimageCO.gif";

But the interpretation is this:


I do not know like separating the last variable with the rest of the name of the file ->

I have verified this script works doing annotation tests, and has tried several times to open the file of the previous day (day 26). Thanks for the aid, it would be very important my to solve this problem, product of my limited PHP knowledge.

01-27-2004, 07:31 PM

$filename = "http://www.elpais.es/diario/media/$anol$mesl/$diac/opinion/vinetas/".$anol."".$mesl."".$dialimage."CO.gif";

$filename1 = "http://www.elpais.es/diario/media/$anol$mesl/$diac/opinion/vinetas/".$anol."".$mesl."".$dialaimage."CO.gif";

01-27-2004, 09:08 PM
Perfect. Now yes. Thank you very much.

In few hours I confirm that script works.

Thanks again. This forum is wonderfull.