60c06b00d47a2be5565c300332e44bca353e14ef
[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       if($width == 0) {
29          $fullpath = $this->parent->translate_path($details['directory_path'])  ."/". $details['name'];
30       }
31       else {
32          $fullpath = $this->parent->translate_path($details['directory_path'])  ."/thumbs/". $width ."_". $details['name'];
33       }
34
35       $tmp = getimagesize($fullpath);
36       $mime = $tmp['mime'];
37
38       Header("Content-Type: ". $mime);
39       Header("Content-Length: ". filesize($fullpath));
40       Header("Content-Transfer-Encoding: binary\n");              
41       Header("Content-Disposition: inline; filename=\"". $details['name'] ."\"");
42       Header("Accept-Ranges: bytes");                             
43       Header("Connection: close");                                
44    
45       $file = fopen($fullpath, "rb");
46       fpassthru($file);
47       @fclose($file);
48
49    } // show()
50
51 }
52
53 if(isset($_GET['idx']) && is_numeric($_GET['idx'])) {
54
55    if(isset($_GET['width']) && is_numeric($_GET['width'])) 
56       $width = $_GET['width'];
57    else
58       $width = "";
59
60    $img = new PHPFSPOT_IMG;
61    $img->show($_GET['idx'], $width);
62 }
63
64 ?>