Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: [Solved]: Merging description data from an existing xml file into the description field  (Read 2727 times)

0 Members and 1 Guest are viewing this topic.

chrisv

  • Coppermine newbie
  • Offline Offline
  • Posts: 2

I'm running Coppermine version 1.4.21 with Apache 2 on a Ubuntu 8.04 OS.  I have a collection of about 5000 images that I've successfully imported into Coppermine.  Each of these photos has a unique filename such as 001.jpg, 002.jpg, etc.  I'd like to add descriptive information about each of these photos within coppermine. From a previous image program, I have a single XML file that has a description for each of the 5000 images.  Is there a way to take the description from the XML file and somehow merge it into the Coppermine description field so that I don't have to manually cut and paste this information for each image?  Here is a sample of the xml file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE GreenstoneDirectoryMetadata SYSTEM "http://greenstone.org/dtd/GreenstoneDirectoryMetadata/1.0/GreenstoneDirectoryMetadata.dtd">
<DirectoryMetadata>
   <FileSet>
      <FileName>001.jpg</FileName>
      <Description>
         <Metadata name="Title">Northington and Bordeaux Cash Grocery</Metadata>
         <Metadata name="Filename">1</Metadata>
         <Metadata name="Publisher">Huntsville Arts Commission</Metadata>
         <Metadata name="Creator">n/a</Metadata>
         <Metadata name="Date">1950</Metadata>
         <Metadata name="Place">Sam Houston Avenue</Metadata>
         <Metadata name="Type">Image</Metadata>
         <Metadata name="Description">Northington and  Boudreaux Cash Grocery, west side of Sam Houston Avenue, ca. 1950, present day (2003) location of Sam Houston Antique Mall.</Metadata>
      </Description>
   </FileSet>
   <FileSet>
      <FileName>002.jpg</FileName>
      <Description>
         <Metadata name="Title">President's residence, Sam Houston State Teachers College</Metadata>
         <Metadata name="Filename">2</Metadata>
         <Metadata name="Publisher">Huntsville Arts Commission</Metadata>
         <Metadata name="Creator">n/a</Metadata>
         <Metadata name="Date">1940</Metadata>
         <Metadata name="Place">Sam Houston State Teachers College
         </Metadata>
         <Metadata name="Type">Image</Metadata>
         <Metadata name="Description">President's residence, Sam Houston State Teachers College</Metadata>
      </Description>
   </FileSet>
« Last Edit: April 21, 2009, 10:34:30 pm by Nibbler »
Logged

Nibbler

  • Guest

Should be able to do this with the script below. Set the path to the xml file where indicated, upload it into your Coppermine directory and run from your browser.

Code: [Select]
<?php

define
('IN_COPPERMINE'true);
require 
'include/init.inc.php';

// Set path to source xml file here
$source 'data.xml';

$xml simplexml_load_file($source);

foreach (
$xml as $file) {
    
    
$filename addslashes($file->FileName);
    
    
$result $file->xpath('Description/Metadata[@name="Title"]');
    
$title addslashes($result[0]);
    
    
$result $file->xpath('Description/Metadata[@name="Description"]');
    
$caption addslashes($result[0]);
    
    
$sql "UPDATE {$CONFIG['TABLE_PICTURES']} SET title = '$title', caption = '$caption' WHERE filename = '$filename'";
    
cpg_db_query($sql);
    
    echo 
"<p>Set '$filename' to title '$title' and caption '$caption'</p>";
}
Logged

chrisv

  • Coppermine newbie
  • Offline Offline
  • Posts: 2

Nibbler,

The script worked great.  You just saved me at least 2 days worth of work.  Thank you,
Logged
Pages: [1]   Go Up
 

Page created in 0.027 seconds with 19 queries.