Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    To load image conditionally

    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.

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    PHP Code:

    $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.'">');

    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #3
    New Coder
    Join Date
    Jan 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    http://www.name.es/diario/media/2004...as_1_G_SCO.gif

    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:

    http://www.name.es/diario/media/2004...vinetas/200401

    I do not know like separating the last variable with the rest of the name of the file ->
    $dial
    or
    $diala
    and
    imageCO.gif

    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.

  • #4
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts
    try:

    $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";
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #5
    New Coder
    Join Date
    Jan 2004
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perfect. Now yes. Thank you very much.

    In few hours I confirm that script works.

    Thanks again. This forum is wonderfull.


  •  

    Posting Permissions

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