Here it is!
Please note the following:
- Make sure you have a backup of your pictures!
- Use it on your own risk!
- Make sure you have a backup of your pictures!
- Do not use it in a functioning Coppermine installation
- Make sure you have a backup of your pictures!
- It is tested and created to be used with PHP CLI (command line interface) so you need shell access.
- Make sure you have a backup of your pictures!
- Modify the parts of the strings in capital letters to suite your own setup.
- Make sure you have a backup of your pictures!
- Everything will be inserted into the first users account.
- Make sure you have a backup of your pictures!
- I call this a hack because it's not using any CM functionality accept from the config.inc.php and it doesn't check if you have logged in to CM.
- Make sure you have a backup of your pictures!
- I slammed this script up to meet my settings and prefferences, they may not meet yours.
- Make sure you have a backup of your pictures!
Have any questions? Please post, then i'll try to answer them.
Did i already mention: "Make sure you have a backup of your pictures!"?
<?php
include '/FULL PATH TO THE FOLDER WHERE THE NEXT FILE IS LOCATED/config.inc.php';
$CONN = mysql_connect($CONFIG["dbserver"],$CONFIG["dbuser"],$CONFIG["dbpass"]) or die ("dead!!");
$searchpath = '/FULL PATH OF YOUR COPPERMINE INSTALL/albums/userpics/INCLUDING USERNAME OR ID';
$basepath = '/FULL PATH OF YOUR COPPERMINE INSTALL/albums/';
$basealbumpath = 'userpics/USERNAME OR ID/';
$it = new RecursiveDirectoryIterator($searchpath);
foreach(new RecursiveIteratorIterator($it) as $file)
{ /* echo $file . "\n";*/
$shortfile = str_replace ($basepath, "", $file);
if (substr($shortfile, -2) != '/.')
{ if (substr($shortfile, -3) != '/..')
{ $basefile = basename($shortfile);
if ((substr($basefile,0,7) != 'normal_') and (substr($basefile,0,6) != 'thumb_'))
{ $shortdir = str_replace("/".$basefile,"",$shortfile);
$albumname = str_replace($basealbumpath,"", $shortdir);
$file_size = filesize($file);
list($width,$height) = getimagesize($file);
$ctime = filectime($file);
$NORMAL = $searchpath."/".$shortdir."/normal_".$basefile;
$THUMB = $searchpath."/".$shortdir."/thumb_".$basefile;
//echo $NORMAL ."\n";
$TOTALFILESIZE = $file_size;
if (file_exists($NORMAL))
{ $TOTALFILESIZE = $TOTALFILESIZE + filesize($NORMAL);
}
if (file_exists($THUMB))
{ $TOTALFILESIZE = $TOTALFILESIZE + filesize($THUMB);
}
/*
echo "FILE: ".$file . "\n";
echo "SHORTFILE: ".$shortfile . "\n";
echo "SHORTDIR: ".$shortdir . "\n";
echo "FILE_SIZE: ".$file_size . "\n";
echo "WIDTH: ".$width . "\n";
echo "HEIGHT: ".$height . "\n";
echo "CTIME: ".$ctime . "\n";
*/
$query = 'select aid from `'.$CONFIG["dbname"].'`.'.$CONFIG["TABLE_PREFIX"].'albums where title = "'.$albumname.'"';
//echo $query . "\n";
$albumid = mysql_fetch_assoc(mysql_query($query));
if (empty($albumid))
{ echo "Adding folder: ".$shortdir."\n";
$albumcreatequery = 'insert into `'.$CONFIG["dbname"].'`.'.$CONFIG["TABLE_PREFIX"].'albums
(title,description,visibility,uploads,comments,votes,pos,category,owner,thumb,keyword,alb_password,alb_password_hint, moderator_group,alb_hits)
values ("'.$albumname.'","",0,"NO","YES","YES",1000,10001,1,0,NULL,NULL,NULL,0,0)';
// echo $albumcreatequery . "\n";
mysql_query($albumcreatequery);
$query = 'select aid from `'.$CONFIG["dbname"].'`.'.$CONFIG["TABLE_PREFIX"].'albums where title = "'.$albumname.'"';
//echo $query . "\n";
$albumid = mysql_fetch_assoc(mysql_query($query));
}
$query = 'select pid from `'.$CONFIG["dbname"].'`.'.$CONFIG["TABLE_PREFIX"].'pictures where filepath = "'.$shortdir.'/" and filename = "'.$basefile.'"';
//print $query. "\n";
$pictureid = mysql_fetch_assoc(mysql_query($query));
if (empty($pictureid))
{ echo "Adding file : ".$basefile." - ".$shortdir."\n";
$filecreatequery = 'insert into `'.$CONFIG["dbname"].'`.'.$CONFIG["TABLE_PREFIX"].'pictures
(aid,filepath,filename,filesize,total_filesize,pwidth,pheight,hits,mtime,
ctime,owner_id,pic_rating,votes,title,caption,keywords,approved,galleryicon,
user1,user2,user3,user4,url_prefix,pic_raw_ip, pic_hdr_ip,lasthit_ip,position,guest_token )
values ("'.$albumid["aid"].'","'.$shortdir.'/","'.$basefile.'","'.$file_size.'","'.$TOTALFILESIZE.'","'.$width.'","'.$height.'",0,"0000-00-00 00:00:00",
"'.$ctime.'",1,0,0,"","","","YES",0,
"","","","",0,"","",NULL,0,"")';
// echo $filecreatequery . "\n";
mysql_query($filecreatequery);
}
}
}
}
}
mysql_close($conn);
?>