134 |
134 |
135 if ( !file_exists($filename) ) |
135 if ( !file_exists($filename) ) |
136 die('Can\'t retrieve image file ' . $filename); |
136 die('Can\'t retrieve image file ' . $filename); |
137 |
137 |
138 $contents = file_get_contents($filename); |
138 $contents = file_get_contents($filename); |
|
139 // expire images 30 days from now |
|
140 $expiry = time() + ( 30 * 86400 ); |
139 |
141 |
140 header('Content-type: ' . $mimetype); |
142 header('Content-type: ' . $mimetype); |
141 header('Content-length: ' . strlen($contents)); |
143 header('Content-length: ' . strlen($contents)); |
142 header('Last-Modified: ' . date('r', $row['img_time_mod'])); |
144 header('Last-Modified: ' . date('r', $row['img_time_mod'])); |
|
145 header('Expires: ' . date('r', $expiry)); |
|
146 |
|
147 // check for not-modified condition |
|
148 if ( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) ) |
|
149 { |
|
150 $time = @strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']); |
|
151 if ( ( !empty($time) && intval($row['img_time_mod']) <= $time ) || date('r', $row['img_time_mod']) === $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) |
|
152 { |
|
153 header('HTTP/1.1 304 Not Modified'); |
|
154 $db->close(); |
|
155 exit; |
|
156 } |
|
157 } |
143 |
158 |
144 if ( isset($_GET['download']) ) |
159 if ( isset($_GET['download']) ) |
145 { |
160 { |
146 // determine an appropriate non-revealing filename |
161 // determine an appropriate non-revealing filename |
147 $filename = str_replace(' ', '_', $row['img_title']); |
162 $filename = str_replace(' ', '_', $row['img_title']); |