Roughed out a vague idea - I might be going about it in a really stupid manner.
Reader please comment if you see any dangers or silly stuff.
Not yet working code by a long chalk, please don't blindly cut, paste and run
<?php
**********************************************
**********************************************
// NON - WORKING, UNTESTED CODE //
// DANGER OF DAMAGE //
**********************************************
**********************************************
please view as 'pseudocode' only for comment.
only run it if you really think you know what
you're doing, because I don't.
// let's define a few vars
// where does coppermine live?
$coppermine_root_directory = '/home/northwes/public_html/gallery/';
// walk like a coppermine and quack like a coppermine.
define('IN_COPPERMINE', true);
// maximum filesize in bytes (we should pull this from the DB really)
$biggestpictureallowed = 150000;
// with any luck, we can now pull in some connectivity using
// cpg's init.inc.php include, which will ask the database for us.
// but since we are an include called from god-knows-where, we must
// set the current working directory first, after saving the previous one.
$cachedcwd = getcwd();
chdir($coppermine_root_directory);
require('include/init.inc.php');
// hopefully now, we know the rough neigbourhood the user uploads
// directories are in
$useruploaddirs = $CONFIG['fullpath'] . $CONFIG['userpics'];
// and can echo it out if we want.
echo $useruploaddirs . "\n";
// and we now know the value of FIRST_USER_CAT
echo FIRST_USER_CAT . "\n";
// Done with cpg's init.inc.php, attention back to the original directory please
chdir($cachedcwd);
// Now then.
// Who is the user?
// Using SMF & SMF-CPG integration here, modify to your taste
$ourusersid = 62; // (I am lazy, needs to be thrashed out. can probably get it from SMF $context array or something)
// So.. what is his directory?
$ouruserscpgdir = $useruploaddirs . "/" . (FIRST_USER_CAT + $ourusersid) . "/";
// echo that out for checking
echo $ouruserscpgdir . "\n";
// This code is being run as some kind of larger script that has just accepted a
// file upload, from a HTML form with an <INPUT TYPE="FILE" NAME="galleryupload"... field.
// So we can grab a picture out of the $_FILES php variable.
// Do a bit of basic type / size checking, not much, could do better
if ((($_FILES["galleryupload"]["type"] == "image/gif")
|| ($_FILES["galleryupload"]["type"] == "image/jpeg")
|| ($_FILES["galleryupload"]["type"] == "image/pjpeg"))
&& ($_FILES["galleryupload"]["size"] < $biggestpictureallowed))
{
if(!$_FILES["galleryupload"]["error"] > 0)
{
// maybe user has never been before, if not, make his dir
// mildly problematic, this produces folders that you can't
// delete over ftp. tip, write a script using 'unlink' to get rid
// if in a tight spot. needs fixing.
if (!file_exists("$ouruserscpgdir))
{
mkdir("$ouruserscpgdir);
}
// check this file(name) hasn't already been added
// if not, add it to our user's coppermine folder
if(!file_exists("$ouruserscpgdir . $_FILES["galleryupload"]["name"]))
{
move_uploaded_file($_FILES["galleryupload"]["tmp_name"], $ouruserscpgdir . $_FILES["galleryupload"]["name"]);
}
}
}
// okay that should have grabbed the incoming file and stuffed it
// into the correct user's coppermine folder.
// now we have to add it into the database properly, into a
// specified album.
// attention back onto coppermine
chdir($coppermine_root_directory);
// get hold of picmgmt.inc.php
require('include/init.inc.php');
// now we want to call picmgmt.inc.php's add_picture() function
// modify the arguments as required;
$whichalbum = 1;
$cpgpicfilepath = $ouruserscpgdir;
$cpgpicfilename = $_FILES["galleryupload"]["name"];
$cpgposition = 0;
$cpgtitle = "";
$cpgcaption = "";
$cpgkeywords = "";
$cpguser1 = $ourusersid;
$cpguser2 = "";
$cpguser3 = "";
$cpguser4 = "";
$cpgcategory = 0;
$cpgrawIP = "";
$cpghdrIP = "";
$cpgpicwidth = 0;
$cpgpicheight = 0;
add_picture($whichalbum,
$cpgpicfilepath,
$cpgpicfilename,
$cpgposition,
$cpgtitle,
$cpgcaption,
$cpgkeywords,
$cpguser1,
$cpguser2,
$cpguser3,
$cpguser4,
$cpgcategory,
$cpgrawIP,
$cpghdrIP,
$cpgpicwidth,
$cpgpicheight)
// return attention to the original script
chdir($cachedcwd);
// and that should be done
?>