plugins/gallery/fetcher.php
changeset 30 689b095d02cf
parent 28 36ea553da7ba
child 42 7c6e2e97aa08
--- a/plugins/gallery/fetcher.php	Thu Jan 29 01:30:09 2009 -0500
+++ b/plugins/gallery/fetcher.php	Thu Jan 29 02:03:47 2009 -0500
@@ -136,10 +136,25 @@
     die('Can\'t retrieve image file ' . $filename);
   
   $contents = file_get_contents($filename);
+  // expire images 30 days from now
+  $expiry = time() + ( 30 * 86400 );
   
   header('Content-type: '   . $mimetype);
   header('Content-length: ' . strlen($contents));
   header('Last-Modified: '  . date('r', $row['img_time_mod']));
+  header('Expires: ' . date('r', $expiry));
+  
+  // check for not-modified condition
+  if ( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) )
+  {
+    $time = @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']);
+    if ( ( !empty($time) && intval($row['img_time_mod']) <= $time ) || date('r', $row['img_time_mod']) === $_SERVER['HTTP_IF_MODIFIED_SINCE'] )
+    {
+      header('HTTP/1.1 304 Not Modified');
+      $db->close();
+      exit;
+    }
+  }
   
   if ( isset($_GET['download']) )
   {