Herself's Webtools

Scripts, HowTos, Templates, Plugins, Widgets, Tips

Archive for the ‘coppermine’ Category

How to add photos from Coppermine to any PHP page

without comments

Some asked how to add Coppermine photos to WordPress pages. This code will work for any page.

You need to replace MYSQL_SERVER with your database server, localhost usually works just fine.
USER_NAME is the user name for your Coppermine database
PASSWORD is the password for your Coppermine database
DATABASE_NAME is the name of your Coppermine database

Also replace YOUR_DOMAIN with the domain your Coppermine albums are hosted on. You might also need to change the path.

This code will give you a horizontal table of 3 thumbnail photos.

If you are using WordPress, you need to download any page from your theme. Change the file name to Coppermine and the Template name to Coppermine.

Remove the stuff in the middle. On my template that is everything between<div id=”content” class=”page”> and </div> but your template might be different.  The past this code into that section being sure to add your password, database etc.

When you are done, upload the new template to your theme directory.

Create a new page and choose Coppermine as the template.  All the work is done.  You can add text or anything else to the page.

if ( !($coppermine_db = mysql_connect( “MYSQL_SERVER”, “USER_NAME”, “PASSWORD” ))){
die ( “Can not connect to server” );
//select db
if ( !(mysql_select_db(“DATABASE_NAME”, $coppermine_db ))){
die ( “Can not select database” );

//ask mysql db for the path and file name of last five images uploaded
$coppermine_query = “select filepath, filename, ctime from cpg_pictures order by ctime desc limit 3;”;

$coppermine_result = mysql_query($coppermine_query);
$count = mysql_numrows( $coppermine_result );

//start link
$link =  “<center>”;

$link .= “<table border=3>”;
$link .=  “<th colspan=3><a href=\”http://YOUR_DOMAIN.com/coppermine/\”>Recent Photos</th><tr>”;
$i = 0;
while ( $i < $count ){

$path = mysql_result($coppermine_result, $i, “filepath” );
$name = mysql_result($coppermine_result, $i, “filename” );

$link .= “<td><img src=\”http://YOUR_DOMAIN.com/coppermine/albums/$path” . “thumb_$name\”></td>”;

$link .= “</tr></table>”;
$link .= “</center>”;

//end link

//clean up

print $link;

You can see an example of this code TimesToCome where I pull 3 photos from 3 different Coppermine albums onto the page.

Written by Linda MacPhee-Cobb

September 22nd, 2008 at 4:24 pm

Yet another Coppermine MySQL injection flaw has been discovered

without comments

Coppermine 1.4.19 has been released to fix a MySQL injection flaw, again. This is how TimesToCome was hacked last April and why you now have all these shiny new security tools and information on this website.

I went to the Coppermine site only because there was a huge increase in cross site scripting attempts last night on the Coppermine albums.

Anyhow update if you have not.

Written by Linda MacPhee-Cobb

August 6th, 2008 at 1:21 pm

WordPress Blue-box theme converted for Coppermine users

without comments

Here is another popular WordPress Theme ( Blue-Box) I converted to work with Coppermine. You should find it easy to tailor to your needs including adding in advertising to your sidebar. Coppermine Blue-Box WordPress adapted theme

Written by Linda MacPhee-Cobb

May 12th, 2008 at 5:00 am

How to move Coppermine to a new server

with 2 comments

I’ve known for a few months I needed to move to another hosting company but I kept putting it off because the thought of redoing all the Coppermine stuff horrified me.

It turned out to be pretty easy. OK after 4 hours of going in circles I now know how to do it and it is easy now.

Backup old stuff:
Download your entire Coppermine directory from your old host to your home computer. This may take a while if you have lots of pictures.

Using whatever tools your webhost provides backup and download your Coppermine MySQL database. Most hosts use phpMyAdmin. If you have that available select your Coppermine database; Select Export; Select Save as file; Give it a file name ( template ) and download it with no compression.

Upload to new server:
Upload your entire Coppermine directory to your new webhost ( this may take a while )

Create a new database for Coppermine on your new host using what ever tools the host provides. Write down your user name, database name, and server if it gives you a server name. ( Most of the time it will be on the same server and you will just use localhost. )

Import the old database to the new database. If you are using phpMyAdmin, select the database; Select Import; chose the file and upload.

If you get permissions errors from MySQL while importing your data base try this: On your computer open your database backup you downloaded in a text editor. It is a plain text file you can easily work with it. ( Make a copy first of course! ) Remove every thing until the lines

— Table structure for table ‘cpg_albums’

Leave those lines and every thing after them in the file but remove the lines before that. The user name, database, CREATE DATABASE etc are all what is causing the permissions problem. Dump the lines below – yours will be slightly different.

— phpMyAdmin SQL Dump
— version
— http://www.phpmyadmin.net

— Host:
— Generation Time: Mar 11, 2008 at 02:06 PM
— Server version: 4.1.22
— PHP Version: 4.4.4

— Database: `her0731003345419`

CREATE DATABASE `her0731003345419` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `her0731003345419`;

— ——————————————————–

— Table structure for table `cpg_albums`

It took me several hours to find that information. It is not well documented anywhere. The rest of the move was painless.

The last thing you have to do now is to change your user name, host and database name in your config.inc.php file to use your new database. You’ll find this file in Coppermine/includes. Just edit the entries and remove your old user name, password and host and enter your new password, host and database name.

Written by Linda MacPhee-Cobb

April 14th, 2008 at 5:00 am