1) { error('Multiple matches on:', $query); } /* Fetch the result as an object. */ $esta = pg_fetch_object($result, 0); if(! $esta) { error('pg_fetch_object: ' . pg_ErrorMessage($dbh)); } pg_close($dbh); $file = $idir . '/' . (($field == 'thumbnail') ? 'th' : '') . $esta->id . '.jpg'; if(!file_exists($file)) { error('No photo:', $query); } if(!($fd = fopen($file, 'r'))) { error('file open failed'); } /* We expect to succeed now. Emit the MIME type. */ header('Content-type: image/jpeg'); /* Emit the image data. */ $content = fread($fd, filesize($file)); echo($content); /* Close up shop. */ exit; /* error() * * Emit an error graphic in GIF format. */ function error() { $msg = func_get_arg(0); $detail = (func_num_args() >= 2) ? func_get_arg(1) : ''; global $thumb; if(strlen($thumb)) { $width = 100; $height = 150; $size = 9; $size2 = 6; $x = 2; $y = 12; $x2 = 4; $y2 = 22; } else { $width = 300; $height = 450; $size = 20; $size2 = 15; $x = 15; $y = 35; $x2 = 24; $y2 = 55; } $im = ImageCreate($width, $height); $backgroundColor = ImageColorAllocate($im, 204, 204, 255); $textColor = ImageColorAllocate($im, 0, 0, 51); /* (image, size, angle, x, y, color, font, message) */ ImageTTFText($im, $size, 0, $x, $y, $textColor, 'verdana.ttf', $msg); if(strlen($detail)) { ImageTTFText($im, $size, 0, $x2, $y2, $textColor, 'verdana.ttf', $detail); } header('Content-type: image/gif'); ImageGif($im); exit; } /* end error() */