issue14, thumbs are now stored outside F-Spot's directory structure
[phpfspot.git] / phpfspot_img.php
1 <?php
2
3 require_once "phpfspot.class.php";
4
5 class PHPFSPOT_IMG {
6    
7    var $db;
8    var $parent;
9
10    public function __construct()
11    {
12       $this->parent = new PHPFSPOT;
13       $this->db = $this->parent->db;
14
15    } // __construct()
16
17    public function __destruct()
18    {
19
20    } // __desctruct()
21
22    public function show($idx, $width = 0)
23    {
24       $this->parent->gen_thumb($idx);
25
26       $details = $this->parent->get_photo_details($idx);
27
28       /* show original photo */
29       if($width == 0) {
30          $fullpath = $this->parent->translate_path($details['directory_path'])  ."/". $details['name'];
31       }
32       /* show thumbnail */
33       else {
34          $fullpath = $this->parent->cfg->base_path ."/thumbs/". $width ."_". $this->parent->getMD5($idx);
35       }
36
37       if(!file_exists($fullpath)) {
38          $this->parent->gen_thumb($idx, 0, 1);
39       }
40       if(!is_readable($fullpath)) {
41          die("File ". $fullpath ." is not readable. Check the permissions");
42       }
43
44       $tmp = getimagesize($fullpath);
45       $mime = $tmp['mime'];
46
47       Header("Content-Type: ". $mime);
48       Header("Content-Length: ". filesize($fullpath));
49       Header("Content-Transfer-Encoding: binary\n");              
50       Header("Content-Disposition: inline; filename=\"". $details['name'] ."\"");
51       Header("Accept-Ranges: bytes");                             
52       Header("Connection: close");                                
53    
54       $file = fopen($fullpath, "rb");
55       fpassthru($file);
56       @fclose($file);
57
58    } // show()
59
60 }
61
62 if(isset($_GET['idx']) && is_numeric($_GET['idx'])) {
63
64    if(isset($_GET['width']) && is_numeric($_GET['width'])) 
65       $width = $_GET['width'];
66    else
67       $width = "";
68
69    $img = new PHPFSPOT_IMG;
70    $img->show($_GET['idx'], $width);
71 }
72
73 ?>