simple if then statement

Discussion in 'PHP' started by LongBeachIsland, Feb 19, 2010.

  1. #1
    I have very little knowledge of php. I am trying to put together a very simple script everything is working it is very short and simple however. I am utilizing a get function to pull images from a website. I would like to only get the image/images if it is older then 15 minutes. My current code is
    
    <?php 
    $weatherradar = file_get_contents('http://radar.weather.gov/Conus/Loop/northeast_loop.gif');
    
    $fp = fopen('image.gif', 'w');
    fwrite($fp, $weatherradar);
    fclose($fp); 
     ?>
    
    PHP:
    Now It should be a simple bit of code to use but I have know idea of what the code would be, any help would be greatly appreciated. Basically I just want to only get and replace the image if it is older then 15 minutes.

    Thanks in advance for any help.
     
    LongBeachIsland, Feb 19, 2010 IP
  2. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #2
    <?
    
    $fn = 'image.gif';
    if (!file_exists($fn) || filemtime($fn) + 15*60 < time())
    {
     //insert get file code here
    }
    
    ?>
    PHP:
     
    wmtips, Feb 19, 2010 IP
  3. LongBeachIsland

    LongBeachIsland Peon

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks a lot, you saved me a great deal of time believe it or not. It is not that I am too lazy to look it up it just takes forever to find what you are actually looking for.
    Thanks again
     
    LongBeachIsland, Feb 19, 2010 IP