]> git.wh0rd.org Git - tt-rss.git/blob - image.php
image.php: replace file_get_contents() with a fread/print loop
[tt-rss.git] / image.php
1 <?php
2         set_include_path(dirname(__FILE__) ."/include" . PATH_SEPARATOR .
3                 get_include_path());
4
5         require_once "config.php";
6
7         // backwards compatible wrapper for old-style image caching
8         /* if (isset($_GET['url'])) {
9                 $url = base64_decode($_GET['url']);
10
11                 $filename = CACHE_DIR . '/images/' . sha1($url) . '.png';
12
13                 if (file_exists($filename)) {
14                         header("Content-type: image/png");
15                         echo file_get_contents($filename);
16                 } else {
17                         header("Location: $url");
18                 }
19
20                 return;
21         } */
22
23         @$hash = basename($_GET['hash']);
24
25         if ($hash) {
26
27                 $filename = CACHE_DIR . '/images/' . $hash . '.png';
28
29                 if (file_exists($filename)) {
30                         header("Content-type: image/png");
31                         $stamp = gmdate("D, d M Y H:i:s", filemtime($filename)). " GMT";
32                         header("Last-Modified: $stamp", true);
33
34                         $fp = fopen($filename, "r");
35
36                         if ($fp) {
37                                 while ($data = fread($fp, 32768)) {
38                                         print $data;
39                                 }
40                                 fclose($fp);
41                         }
42
43                 } else {
44                         header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
45                         echo "File not found.";
46                 }
47         }
48
49 ?>