<?php
// ------------------------------------------------------------------------- //
// Coppermine Photo Gallery 1.2.1                                            //
// ------------------------------------------------------------------------- //
// Copyright (C) 2002,2003 Gregory DEMAR                                     //
// http://www.chezgreg.net/coppermine/                                       //
// ------------------------------------------------------------------------- //
// Updated by the Coppermine Dev Team                                        //
// (http://coppermine.sf.net/team/)                                          //
// see /docs/credits.html for details                                        //
// ------------------------------------------------------------------------- //
// This program is free software; you can redistribute it and/or modify      //
// it under the terms of the GNU General Public License as published by      //
// the Free Software Foundation; either version 2 of the License, or         //
// (at your option) any later version.                                       //
// ------------------------------------------------------------------------- //


define('IN_COPPERMINE', true);
define('GETFILE_PHP', true);

require('include/init.inc.php');

global $CONFIG, $HIDE_USER_CAT, $FORBIDDEN_SET, $ALBUM_SET, $cpg_show_private_album;
$album_filter='';
if (!empty($FORBIDDEN_SET) && !$cpg_show_private_album):
	$album_filter = ' and '.str_replace('p.','',$FORBIDDEN_SET);
endif;

function mime_content_type($path) {
	$image_params = getimagesize($path);
	if (is_null($image_params)):
		return null;
	else:
		return $image_params['mime'];
	endif;
}

$pid = (int) $_GET['id'];

cpg_db_connect();
$result = mysql_query("SELECT filepath,filename,pwidth,pheight,url_prefix,filesize FROM {$CONFIG['TABLE_PICTURES']} WHERE pid=$pid ". $ALBUM_SET . $album_filter .";");
$result = mysql_fetch_assoc($result);
mysql_close();

if (!$result):
	die();
endif;

$cfilepath = $CONFIG['fullpath'].$result['filepath']."thumb_".$result['filename'];

header("Content-type: ".mime_content_type($cfilepath));
header("Content-Disposition: inline; filename=thumb_".$result['filename']);

echo fread(fopen($cfilepath, "rb"), filesize($cfilepath));
?>
