Location: PHPKode > scripts > Dr-Fun grabber > dr-fun-grabber/index.php
<?php

    /** 
    Dr-Fun grabber 1.0.0: Grab and cache Dave Farley's daily Dr-Fun cartoon.

    You can see it in action here:
      http://i.jeremybrand.com/dr-fun

    Copyright (C) 2000  Jeremy Brand 
           email: hide@address.com
           web: http://www.JeremyBrand.com/Jeremy/Brand/Jeremy_Brand.html

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    **/

      set_time_limit(120);

      $home = 'http://www.ibiblio.org/Dave/Dr-Fun/latest.jpg';
      $file = '/var/tmp/dr-fun.jpg';

      $now = time();
      $mtime = filemtime($file);
      $agelimit = 43200;

      $fileage = $now - $mtime;

      if ($fileage > $agelimit)
      {
        $fd = fopen($home, 'r');
        if ($fd)
        {
          $fd2 = fopen($file,'w');
          if ($fd2)
          {
            while(!flock($fd2, 2))
              usleep(500);
            while(!feof($fd))
            {
              $buffer = fread($fd, 1024);
              fwrite($fd2, $buffer, strlen($buffer));
              flock($fd2, 3);
            }
            fclose($fd2);
          }
          fclose($fd);
        }
      }

      header('Content-Type: image/jpeg');
      header('Content-Length: ' . filesize($file));
      readfile($file);

?>
Return current item: Dr-Fun grabber