removed temp text and inserted a much better text into
[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("File ". $fullpath ." does not exist");
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       if(!$this->parent->checkifImageSupported($mime)) {
55          $this->parent->showTextImage("Unsupported Image Type");
56          return;
57       }
58
59       Header("Content-Type: ". $mime);
60       Header("Content-Length: ". filesize($fullpath));
61       Header("Content-Transfer-Encoding: binary\n");              
62       Header("Content-Disposition: inline; filename=\"". $details['name'] ."\"");
63       Header("Accept-Ranges: bytes");                             
64       Header("Connection: close");                                
65    
66       $file = fopen($fullpath, "rb");
67       fpassthru($file);
68       @fclose($file);
69
70    } // show()
71
72 }
73
74 if(isset($_GET['idx']) && is_numeric($_GET['idx'])) {
75
76    if(isset($_GET['width']) && is_numeric($_GET['width'])) 
77       $width = $_GET['width'];
78    else
79       $width = "";
80
81    $img = new PHPFSPOT_IMG;
82    $img->show($_GET['idx'], $width);
83 }
84
85 ?>