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: Upload directly to predefined album?  (Read 6755 times)

0 Members and 1 Guest are viewing this topic.

ardeo

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
Upload directly to predefined album?
« on: March 10, 2008, 07:40:16 pm »

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
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Upload directly to predefined album?
« Reply #1 on: March 11, 2008, 07:14:34 am »

Well, only allow uploads to that album then.
Logged

ardeo

  • Coppermine newbie
  • Offline Offline
  • Posts: 5
Re: Upload directly to predefined album?
« Reply #2 on: March 11, 2008, 02:07:33 pm »

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
Logged

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Upload directly to predefined album?
« Reply #3 on: March 12, 2008, 06:42:18 am »

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

argie

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Upload directly to predefined album?
« Reply #4 on: March 24, 2008, 06:08:18 pm »

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? 
Logged

argie

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Upload directly to predefined album?
« Reply #5 on: March 24, 2008, 10:31:24 pm »

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
Logged

argie

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Upload directly to predefined album?
« Reply #6 on: March 25, 2008, 01:25:25 am »

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

Joachim Müller

  • Dev Team member
  • Coppermine addict
  • ****
  • Offline Offline
  • Gender: Male
  • Posts: 47843
  • aka "GauGau"
    • gaugau.de
Re: Upload directly to predefined album?
« Reply #7 on: March 25, 2008, 07:03:47 am »

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

argie

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Upload directly to predefined album?
« Reply #8 on: March 25, 2008, 07:31:39 am »

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

Code: [Select]
$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.

Logged

argie

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Upload directly to predefined album?
« Reply #9 on: March 25, 2008, 03:01:07 pm »

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

Code: [Select]
<?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

?>

Logged

argie

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Upload directly to predefined album?
« Reply #10 on: March 25, 2008, 03:03:45 pm »

^ 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
Logged

Nibbler

  • Guest
Re: Upload directly to predefined album?
« Reply #11 on: March 25, 2008, 03:09:53 pm »

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.
Logged

argie

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Upload directly to predefined album?
« Reply #12 on: March 25, 2008, 04:14:46 pm »

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

argie

  • Coppermine newbie
  • Offline Offline
  • Posts: 8
Re: Upload directly to predefined album?
« Reply #13 on: March 25, 2008, 10:02:11 pm »

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.
Logged
Pages: [1]   Go Up
 

Page created in 0.022 seconds with 19 queries.