forum.coppermine-gallery.net
No Support => General discussion (no support!) => Topic started by: dfstrottersfan on December 23, 2004, 08:00:05 pm
-
I have an application which really looks suited to Coppermine.
I want to load an image gallery - myself but allow only recognised users to access the gallery and read i.e. download the images.
Can anyone tell me if this is possible - I had a quick look at the documentation and it was not obvious to me if this was possible.
I didn't want to invest a lot of time if it was not possible
Thanks in advance
-
How can I let unregistered users see the thumbnails only, but not the actual pictures? (http://coppermine.sourceforge.net/faq.php#viewThumbnailsOnly)
There is a variation on this posted on the boards to make it even more restrictive, or you could use album viewing rights to control access.
-
ok here's what we do:) this is VERY possible. although you must be willing to code ALL of this and to not hold me responsible if anything happans that shouldn't. (back up all the files that will be modifed)
First off, let's create a file called "images.php".
Place this code in it:
<?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. //
// ------------------------------------------------------------------------- //
// Code by: Christopher Brown-Floyd
// Date: January 13, 2004
// Modifed by: Matt H. @ TangibleBrit.com
// Date: December 28, 2004
define('IN_COPPERMINE', true);
define('GETFILE_PHP', true);
global $CONFIG;
include('include/init.inc.php');
include('include/config.inc.php');
$CONFIG['TABLE_CONFIG'] = $CONFIG['TABLE_PREFIX'] . "config";
$CONFIG['TABLE_PICTURES'] = $CONFIG['TABLE_PREFIX'] . "pictures";
error_reporting (0);
// Begin Authenticate User
if(!USER_ID){
header("Location: index.php");
exit;
}
//End Atuhenticate User
db_connect($db);
$results = mysql_query("SELECT * FROM {$CONFIG['TABLE_CONFIG']}");
while ($row = mysql_fetch_array($results)) {
$CONFIG[$row['name']] = $row['value'];
} // while
mysql_free_result($results);
// Set error logging level
if ($CONFIG['debug_mode']) {
error_reporting (0);
} else {
error_reporting (0);
}
mysql_close();
if (!function_exists('mime_content_type'))
{
function mime_content_type($path) {
$image_params = getimagesize($path);
if (is_null($image_params))
return null;
else
return $image_params['mime'];
}
}
$pic_prefix = array(
'thumb' => $CONFIG['thumb_pfx'],
'normal' => $CONFIG['normal_pfx'],
'fullsize' => '',
);
$pid = (int) $_GET['pid'];
$size = htmlspecialchars($_GET['size']);
db_connect($db);
$result = mysql_query("select filepath,filename from {$CONFIG['TABLE_PREFIX']}pictures where pid=$pid;");
$result = mysql_fetch_assoc($result);
mysql_close();
$filename = $result['filename'];
$cfilepath = $CONFIG['fullpath'].$result['filepath'].$pic_prefix[$size].$result['filename'];
header('Content-type: '.mime_content_type($cfilepath));
header('Content-disposition: inline; filename="' . $filename . '.jpg"');
error_reporting (0);
$fp = fopen($cfilepath,'rb');
echo fread($fp,filesize($cfilepath));
fclose();
function db_connect(&$db)
{
global $CONFIG;
$db = mysql_connect($CONFIG['dbserver'],$CONFIG['dbuser'],$CONFIG['dbpass']);
mysql_select_db($CONFIG['dbname']);
}
?>
Note: That file has already been coded to NOT show images to users who are not logged in; therefore, your images are protected from that point.
Next, let's open up the file "functions.inc.php" in the /include folder.
Replace:
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
With:
if (is_null($pic_row['pid']) || !isset($CONFIG['url_mode']) || $CONFIG['url_mode']!='hide')
return $url_prefix[$pic_row['url_prefix']]. path2url($pic_row['filepath']. $pic_prefix[$mode]. $pic_row['filename']);
return 'get_file.php?pid='.$pic_row['pid'].'&size='.$mode;
Next, open up "config.inc.php" in the /include folder
Add this line to the code:
$CONFIG['url_mode'] = 'hide';
Okay, this will make all of the images in your gallery appear as: images.php?pid=(whatever it is)&size=(the size) instead of http://yousite.com/yourcpgdir/albums/whatever.jpg.
Next, open up the following files: index.php, displayimage.php, and thumbnails.php
To each file, add this code after "define('IN_COPPERMINE', true);"
include("include/init.inc.php");
if(!USER_ID){
header("Location: login.php?referer=$PHP_SELF");
exit;
}
There you go! It should work fine if you do it right, if you have any problems, post back!
-
Seems to me that all he'll need to do is make a custom bridge file. He didn't say he had cpg already installed.