use ignore_once instead of ignore for requirement checks, or rpc.php will fail becaus...
[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       $details = $this->parent->get_photo_details($idx);
25    
26       if(!$details) {
27          $this->parent->showTextImage("The image you requested is unknown");
28          return;
29       }
30
31       /* show original photo */
32       if($width == 0) {
33          $fullpath = $this->parent->translate_path($details['directory_path'])  ."/". $details['name'];
34       }
35       /* show thumbnail */
36       else {
37          $fullpath = $this->parent->cfg->base_path ."/thumbs/". $width ."_". $this->parent->getMD5($idx);
38          if(!file_exists($fullpath)) 
39             $this->parent->gen_thumb($idx, 0, 1);
40       }
41
42       if(!file_exists($fullpath)) {
43          $this->parent->showTextImage("test1");
44          return;
45       }
46       if(!is_readable($fullpath)) {
47          $this->parent->showTextImage("File ". $fullpath ." is not readable. Check the permissions");
48          return;
49       }
50
51       $tmp = getimagesize($fullpath);
52       $mime = $tmp['mime'];
53
54       Header("Content-Type: ". $mime);
55       Header("Content-Length: ". filesize($fullpath));
56       Header("Content-Transfer-Encoding: binary\n");              
57       Header("Content-Disposition: inline; filename=\"". $details['name'] ."\"");
58       Header("Accept-Ranges: bytes");                             
59       Header("Connection: close");                                
60    
61       $file = fopen($fullpath, "rb");
62       fpassthru($file);
63       @fclose($file);
64
65    } // show()
66
67 }
68
69 if(isset($_GET['idx']) && is_numeric($_GET['idx'])) {
70
71    if(isset($_GET['width']) && is_numeric($_GET['width'])) 
72       $width = $_GET['width'];
73    else
74       $width = "";
75
76    $img = new PHPFSPOT_IMG;
77    $img->show($_GET['idx'], $width);
78 }
79
80 ?>