3 /***************************************************************************
5 * Copyright (c) by Andreas Unterkircher, unki@netshadow.at
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 ***************************************************************************/
24 require_once "phpfspot.class.php";
32 * PHPFSPOT_IMG class constructor
34 public function __construct()
36 $this->parent = new PHPFSPOT;
37 $this->db = $this->parent->db;
42 * PHPFSPOT_IMG class destructor
44 public function __destruct()
50 * sends the specified image to the browser
52 * this function will send the specified image to
53 * the client - in the specified width. it also try's
54 * to create on-the-fly missing thumbnails via PHPFSPOT
55 * gen_thumbs function.
57 public function show($idx, $width = 0)
59 $details = $this->parent->get_photo_details($idx);
62 $this->parent->showTextImage("The image you requested is unknown");
66 /* no width specified - show photo in its original size */
68 $fullpath = $this->parent->translate_path($details['directory_path']) ."/". $details['name'];
72 /* if no entry for this photo is yet in the database, create thumb */
73 if(!$this->parent->getMD5($idx)) {
74 $this->parent->gen_thumb($idx);
76 $fullpath = $this->parent->cfg->base_path ."/thumbs/". $width ."_". $this->parent->getMD5($idx);
77 /* if the thumb file does not exist, create it */
78 if(!file_exists($fullpath)) {
79 $this->parent->gen_thumb($idx);
83 if(!file_exists($fullpath)) {
84 $this->parent->showTextImage("File ". basename($fullpath) ." does not exist");
87 if(!is_readable($fullpath)) {
88 $this->parent->showTextImage("File ". basename($fullpath) ." is not readable. Check the permissions");
92 $tmp = getimagesize($fullpath);
95 if(!$this->parent->checkifImageSupported($mime)) {
96 $this->parent->showTextImage("Unsupported Image Type");
100 Header("Content-Type: ". $mime);
101 Header("Content-Length: ". filesize($fullpath));
102 Header("Content-Transfer-Encoding: binary\n");
103 Header("Content-Disposition: inline; filename=\"". $details['name'] ."\"");
104 Header("Accept-Ranges: bytes");
105 Header("Connection: close");
107 $file = fopen($fullpath, "rb");
115 if(isset($_GET['idx']) && is_numeric($_GET['idx'])) {
117 $img = new PHPFSPOT_IMG;
119 if(isset($_GET['width']) && is_numeric($_GET['width']))
120 $img->show($_GET['idx'], $_GET['width']);
122 $img->show($_GET['idx']);