Here is how I did it
1. Copy Gallery's items table to temp table so we do not mess with live data
2. Add a new column to the temp table
ALTER TABLE `Yours_G3_items-new` ADD `album_name` TEXT NOT NULL3. Find out the parent album id of each items and add that data in the new column.
UPDATE Yours_G3_items-new,Yours_G3_items SET Yours_G3_items-new.album_name = Yours_G3_items.title WHERE Yours_G3_items-new.parent_id = Yours_G3_items.id4. Export the new table with "|" as separator and "" as enclosed.
Now the PHP script
<?I Wish there was API where I could import the image from my old hosting company to Flickr directly instead of uploading them via their PC up-loader.
//File to be opened
$file="/tmp/csv.txt";
$gallery_album_base = ..../gallery3/var/albums";
$new_gallery_album_base = <new location>/albums" ;
//
$handle = fopen($file, 'r') or die ("Fail to open input file \n\r") ;
$ln= 0 ;
// Some Functions Start
function csv_explode($delim='|', $str, $enclose='"', $preserve=false){
$resArr = array();
$n = 0;
$expEncArr = explode($enclose, $str);
foreach($expEncArr as $EncItem){
if($n++%2){
array_push($resArr, array_pop($resArr) . ($preserve?$enclose:'') . $EncItem.($preserve?$enclose:''));
}else{
$expDelArr = explode($delim, $EncItem);
array_push($resArr, array_pop($resArr) . array_shift($expDelArr));
$resArr = array_merge($resArr, $expDelArr);
}
}
return $resArr;
}
// iptc_make_tag() function by Thies C. Arntzen
function iptc_make_tag($rec, $data, $value)
{
$length = strlen($value);
$retval = chr(0x1C) . chr($rec) . chr($data);
if($length < 0x8000)
{
$retval .= chr($length >> 8) . chr($length & 0xFF);
}
else
{
$retval .= chr(0x80) .
chr(0x04) .
chr(($length >> 24) & 0xFF) .
chr(($length >> 16) & 0xFF) .
chr(($length >> 8) & 0xFF) .
chr($length & 0xFF);
}
return $retval . $value;
}
// Some Functions End
while ($line = fgets ($handle)){
$line = str_ireplace("\x0D", "", $line);
$line = urldecode ($line);
++$ln;
print ("just line : $ln \n");
if ($line===FALSE) print ("FALSE\n");
else {
//print ("I am $ln \n");
//print ($line) ;
$variables = csv_explode ("|", $line);
//print_r ($variables);
//26(album or photo) 25(title), 13(image_path), 4(details),33(album_name/tag)
if ( $variables[26] == photo ){
//Path new and old path
$old_path = $gallery_album_base . '/' . $variables[13];
$image_name_new = $new_gallery_album_base . '/' . $variables[13];
$path_parts = pathinfo ($image_name_new);
if (!file_exists($path_parts['dirname'])) {
print ("makeing directory {$path_parts['dirname']} \n") ;
mkdir ($path_parts['dirname'], 0777,true);
}
// Set the IPTC tags
$iptc = array(
'2#120' => "$variables[4]",
'2#105' => "$variables[25]",
'2#005' => "$variables[25]",
'2#015' => "$variables[33]",
'2#116' => 'Copyright, www santm com'
);
// Convert the IPTC tags into binary code
$data = '';
foreach($iptc as $tag => $string)
{
$tag = substr($tag, 2);
$data .= iptc_make_tag(2, $tag, $string);
}
// Embed the IPTC data
$content = iptcembed($data, $old_path);
// Write the new image data out to the file.
$fp = fopen($image_name_new, "wb");
fwrite($fp, $content);
fclose($fp);
print ("working on $image_name_new \n");
//$size = getimagesize($image_name_new, $info);
//if(isset($info['APP13']))
//{
// $iptc = iptcparse($info['APP13']);
// var_dump($iptc);
//}
} //end of if photo loop
} // end of else loop
} // end of while loop
# Close the File.
fclose($handle);
?>
More here on major phpfunction
http://www.php.net/function.iptcembed
http://www.php.net/function.pathinfo
http://php.net/manual/fr/function.explode.php


















