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: Passing additional parameter in to upload process  (Read 4995 times)

0 Members and 1 Guest are viewing this topic.

dazzlera145

  • Coppermine newbie
  • Offline Offline
  • Posts: 6
Passing additional parameter in to upload process
« on: December 19, 2011, 10:51:09 pm »

Hi,

I've read the upload sub board and can't see any reference to my exact problem though the thread http://forum.coppermine-gallery.net/index.php/topic,71663.0.html does touch on some espects this.

When uploading a single image or using the bulk flash upload method... I could live without having to  implement via the batch upload as I've no need to use this.... I want to do it pass in one may be two new parameters .. for instance users could click on an 'upload' link on a particular page  from the site  I'm working on (www.justflockto.com) .. When the image(s) are uploaded and added to the database they would be associated with the particular page by writing the pid Id in to a new table with the reference for the page.... This way many users could add images associated with a particular page

I can see a possible solution using the single image upload method and combined with what is is the above thread but at this stage it required a lot of code hacking rather than a plugin..

Does anyone have any ideas where I can start of if any existing plugins have done this?

Many Thanks
Darren
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Passing additional parameter in to upload process
« Reply #1 on: December 20, 2011, 11:13:59 am »

Just to make sure I get what you want to do. You have a (non-Coppermine) website justflockto.com and from that site you want to open the Coppermine upload form with an additional parameter like upload.php?my_param=1234, which should be stored somewhere else outside of the Coppermine tables. Correct?
Logged

dazzlera145

  • Coppermine newbie
  • Offline Offline
  • Posts: 6
Re: Passing additional parameter in to upload process
« Reply #2 on: December 20, 2011, 12:36:42 pm »

Just about yes... Ive got coppermne running on our test bed and will be going live with an 'out of the box' deployment of coppermine shortly...

So the idea is as you say have a link upload.php?myvalue=1234 which will take a single or multiple images uploading to the filesystem & database entries as Coppermine does now... at this point I would like to associate the uploaded pictures(s) with 'myvalue' in a new database table I have created... e.g. a user can upload pictures or a place / hotel / restaurant and these pictures are associated with the listing.

Hopefully that makes sense!
Logged

Αndré

  • Administrator
  • Coppermine addict
  • *****
  • Country: de
  • Offline Offline
  • Gender: Male
  • Posts: 15764
Re: Passing additional parameter in to upload process
« Reply #3 on: December 20, 2011, 01:27:32 pm »

All we have to do is to include that parameter to the upload form (e.g. as a hidden field in the single uploader) and then it should be possible to use the solution from the other thread. But I'm not sure if it can be accomplished completely with a plugin or if we need to modify upload.php.
Logged

dazzlera145

  • Coppermine newbie
  • Offline Offline
  • Posts: 6
Re: Passing additional parameter in to upload process
« Reply #4 on: June 02, 2012, 12:59:48 am »

I just thought I'd update everyone on my progress. I had a spare few hours the other week and resolved this issue, in the end the solution was pretty straightforward.

Some back ground, why did I want to do this in the first place? Well on my website justflockto.com i wanted to allow users to upload pictures that were taken at a particular hotel, restaurant, attraction or even a town or city. All these entities are held in a separate database. So a user clicks on the upload.php link can either use the simple of many method to upload pictures, during the upload process the CPG would then update a separate database table with these passed in variables.

I first tried to pass in the variables in the upload.php form. The method works for the simple single upload method but not the bulk way. You can then change the db_input.php scripts to read these variables etc and update the database. As I said passing the data via the form for the flash method doesn't work.

I then got thinking of how practical passing multiple values between forms was, especially is a user were to click on the upload link from a hotel then from the upload page create new album or navigate away etc and then return to the upload page by some means. I suspect that the passed in variables would be lost and I don't want to change the CPG code all over the place.

So I decided to use PHP sessions. This method works for both upload methods :)

Basically I did the following.

added the following to the beginning of upload.php and db_input.php

if (isset($_REQUEST['appsessionid'])){   
   session_id($_REQUEST['appsessionid']);
}
session_start();



Added the following after the functions in upload.php

//################################# MAIN CODE BLOCK ##################################################

if (!isset($_REQUEST['appsessionid'])){

   //
   // Code to get JustFlockTo Functions
   $appuservar = array();

   // Check whether we are getting JF2Country-Id through _GET or _POST
   if ($superCage->get->keyExists('appuservar0')) {
       $appuservar[0] = $superCage->get->getInt('appuservar0');
   } elseif ($superCage->post->keyExists('appuservar0')) {
       $appuservar[0] = $superCage->post->getInt('appuservar0');
   }

   // Check whether we are getting JF2State-Id through _GET or _POST
   if ($superCage->get->keyExists('appuservar1')) {
       $appuservar[1] = $superCage->get->getInt('appuservar1');
   } elseif ($superCage->post->keyExists('appuservar1')) {
       $appuservar[1] = $superCage->post->getInt('appuservar1');
   }

   // Check whether we are getting JF2City-Id through _GET or _POST
   if ($superCage->get->keyExists('appuservar2')) {
       $appuservar[2] = $superCage->get->getInt('appuservar2');
   } elseif ($superCage->post->keyExists('appuservar2')) {
       $appuservar[2] = $superCage->post->getInt('appuservar2');
   }

   // Check whether we are getting JF2Link-Id through _GET or _POST
   if ($superCage->get->keyExists('appuservar3')) {
       $appuservar[3] = $superCage->get->getInt('appuservar3');
   } elseif ($superCage->post->keyExists('appuservar3')) {
       $appuservar[3] = $superCage->post->getInt('appuservar3');
   }


   // Check whether we are getting Category through _GET or _POST
   if ($superCage->get->keyExists('appuservar4')) {
       $appuservar[4] = $superCage->get->getInt('appuservar4');
   } elseif ($superCage->post->keyExists('appuservar4')) {
       $appuservar[4] = $superCage->post->getInt('appuservar4');
   }

   // Set uservar sessions.Only set these is at least one is set. If none are set the user could be navigating back to upload.php from somewhere else within the gallery directory.

   if (!empty($appuservar[0]) || !empty($appuservar[1]) || !empty($appuservar[2]) || !empty($appuservar[3]) || !empty($appuservar[4])) {

      if (!empty($appuservar[0])){
         $_SESSION['appuservar0'] = $appuservar[0];
      } else {
         $_SESSION['appuservar0'] = null;
      }

      if (!empty($appuservar[1])){
         $_SESSION['appuservar1'] = $appuservar[1];
      } else {
         $_SESSION['appuservar1'] = null;
      }



      if (!empty($appuservar[2])){
         $_SESSION['appuservar2'] = $appuservar[2];
      } else {
         $_SESSION['appuservar2'] = null;
      }



      if (!empty($appuservar[3])){
         $_SESSION['appuservar3'] = $appuservar[3];
      } else {
         $_SESSION['appuservar3'] = null;
      }


      if (!empty($appuservar[4])){
         $_SESSION['appuservar4'] = $appuservar[4];
      } else {
         $_SESSION['appuservar4'] = null;
      }

   }
}
// End



in the include file picmgmt.inc.php there is an add_picture function I added the following


 


       if (isset($_SESSION["appuservar0"])) {
          $var0 = $_SESSION["appuservar0"];
       }

       if (isset($_SESSION["appuservar1"])) {
          $var1 = $_SESSION["appuservar1"];
       }


       if (isset($_SESSION["appuservar2"])) {
          $var2 = $_SESSION["appuservar2"];
       }


       if (isset($_SESSION["appuservar3"])) {
          $var3= $_SESSION["appuservar3"];
       }

       if (isset($_SESSION["appuservar4"])) {
          $var4 = $_SESSION["appuservar4"];
       }

   


   // Update SQL to what ever db table here
   
   cpg_db_query($query);

    // End of JustFlockTo

In the file setup_swf_uploads.js I change the line

        post_params: {"process" : "1", "user" : js_vars.user},
        post_params: {"process" : "1", "user" : js_vars.user, "appsessionid" : js_vars.appsessionid},


I did this as the Swf program pass creates a different PHP session variable to that of the upload.php. If you don't pass the session variable in and set the session the the correct session value then all your session variables are empty.


In upload.php I made the slight change

   if ($upload_form == 'swfupload') {
        // Get the user password hash
        $user_pass = $cpg_udb->get_user_pass(USER_ID);
        // Serialize and base64 encode the password
        set_js_var('user', base64_encode(serialize($user_pass)));

        $appsessionid = session_id();
   set_js_var('appsessionid', $appsessionid);

        set_js_var('user_id', USER_ID);
        set_js_var('allow_guests_enter_file_details', $CONFIG['allow_guests_enter_file_details']);
    }


Here I pass in the correct $appsessionid to the Javascript.




Put it all together and it should work (It works for me on JustFlockTo) There could be a few things missing but you should get the idea





Logged
Pages: [1]   Go Up
 

Page created in 0.022 seconds with 19 queries.