Upload directly to predefined album? Upload directly to predefined album?
 

News:

CPG Release 1.6.26
Correct PHP8.2 issues with user and language managers.
Additional fixes for PHP 8.2
Correct PHP8 error with SMF 2.0 bridge.
Correct IPTC supplimental category parsing.
Download and info HERE

Main Menu

Upload directly to predefined album?

Started by ardeo, March 10, 2008, 07:40:16 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ardeo

Hi.  Is there any way that I could setup a page that would have a simplified upload process that would upload just to one predefined album?  We run photo contests, and it would be great if we could have an upload form that would just allow users to upload directly into the photo contest album.

thanks!
roland

Joachim Müller

Well, only allow uploads to that album then.

ardeo

I'm afraid we wouldn't want to do that, as it would prevent people from uploading into their user albums.  What would be best would be a unique variation of upload.php that pretty much removed all the extra options and just placed the uploads directly into the contest album.  Has anyone ever tried to do that?

thanks,
roland

Joachim Müller

Haven't heard of such a mod. Can't be difficult though. You need it -> you code it.

argie

I would like to code this feature, I need it too. I'm reasonably proficient with php / MySQL but no expert, and don't really know the structure of Coppermine well enough to do it completely without help.

Can anyone suggest any basic pointers that might help get me started?

I currently have a working install of SMF 1.1.4, bridged successfully to CPG 1.4.16 (stable).

It would be nice to be able to write some php that I could insert into SMF's posting screen for specific boards, to allow a direct one-step upload and insert of an image to a specific gallery album.

Which sounds like broadly the same feature that the OP was looking for? 

argie

Got the front end done, & the raw images sat there on the server, it's just how to hook them into coppermine albums now. At which point I'm unsure which way to proceed

argie

proceeding apace but can anyone tell me where $CONFIG['fullpath'] is defined?

Joachim Müller

In include/init.inc.php. Don't edit that manually, but set it on your config screen.

argie

Thanks. I've been through upload.php (wow that's one big file - but really nicely documented) & have come to the conclusion it might be possible to move images into something like


$CONFIG['fullpath'] . $CONFIG['userpics'] . (USER_ID + FIRST_USER_CAT);


after some processing & checking that upload.php would normally do; then call add_picture() from picmgmt.inc.php to do the adding into the database?

But I haven't fully thought it through yet, and my hosting company put an axe through my coppermine installation last night  >:( so I've been distracted.

Get back to it after some sleep.


argie

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

?>


argie

^ that's intended as a drop-in lump of code for SMF's /Sources/post.php BTW, with a hope for easy modification for other applications. Any comments as to what could be done to make that code work & work safely, appreciated - if it should be binned as a bad idea, so be it

Nibbler

You should be able to just make a form and post it to db_input.php?event=picture. That will take care of 99% of the work for you.

argie

Great.. will look into doing it that way. Two thumbs up  :)

argie

Had a look in db_input.php & it looks like it just needs supplying with the following form fields:

form enctype="multipart/form-data"
input type="file" name="userpicture"
input type="hidden" name="album"
input type="hidden" name="title"
input type="hidden" name="caption"
input type="hidden" name="keywords"
input type="hidden" name="user1"
input type="hidden" name="user2"
input type="hidden" name="user3"
input type="hidden" name="user4"

That looks like a great way of doing it, as you say, 99% of the work done.

If the OP has the freedom to do whatever they want with the form that's the way to go  :D

I'm trying to work within the existing SMF posting screen, so that my user can submit a picture to the gallery  within the same form submission click as the usual SMF 'post message' click. Of course that form wants to submit to SMF's processor, function post2() in it's /include/post.php file - so looks like for my interpretation of the issue I'll have to plug on and do the extra work.