Formats Upload Modification - Associate a File with each Image Formats Upload Modification - Associate a File with each Image
 

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

Formats Upload Modification - Associate a File with each Image

Started by Garibaldi, April 17, 2009, 10:54:09 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Garibaldi

I'd like to announce the release of the "Formats Upload" MOD for Coppermine 1.4.x. I needed a solution that would allow me to associate a zip file with each image on my site. This way I could include other files related to that image like an editable photoshop version, a text file with information about that image, etc. This modification adds that same functionality to your Coppermine install. It adds a new button on the Upload page, Edit File page, or Edit Files page. You can select the zip (or other file type) to associate with your image and it is added to the Custom User Field 1 and thus appears right below your image in your gallery for easy access. Here's an example:
http://wiscollectorcar.com/photogallery/albums/userpics/10301/normal_final.JPG

When you upload a file you're presented with this new "Add Formats" button. This same button appears when you click Edit on a picture or edit all the pictures in an album. When you click this button, a new window pops up where you can upload your associated file. Once finished hit done and it will be put automatically into the Other Formats field. You can then save your picture.
http://wiscollectorcar.com/photogallery/albums/userpics/10301/normal_upload.JPG

http://wiscollectorcar.com/photogallery/albums/userpics/10301/normal_upload1.JPG

http://wiscollectorcar.com/photogallery/albums/userpics/10301/normal_upload2.JPG

Here's an example of the similar functionality when you edit an image:
http://wiscollectorcar.com/photogallery/albums/userpics/10301/normal_edit_file.JPG

In addition, if you batch upload pictures, this modification will look for a .zip file in the formats_upload directory that has the same filename as each picture in your batch upload. If that file exists, it will be added automatically to each photo in the batch upload.

I've attached the zip of the files with install instructions.

*NEW* - version 1.2.x will delete the uploaded zip file associated with an image when you delete the image - to upgrade simply follow these instructions

A support topic for this modification is available on the Support Board

2009-07-30- version 1.2.0 now deletes the uploaded file when deleting a picture
2009-06-30- version 1.1.1 bugfix to correct the slashes in the upload URL for Windows servers

2009-06-01- version 1.1.0 added unique filenames for uploads

2009-04-17- version 1.0.0

Garibaldi

###############################################

## MOD Title: Formats Upload

## MOD Author: Garibaldi (Garibaldi@wiscollectorcar.com) http://www.wiscollectorcar.com

## MOD Description: Allows you to associate a file with each image in your gallery, e.g. a zip archive of files related to that image

## MOD Version: 1.1.1

## Installation Level: Easy

## Installation Time: 10 minutes

## Files To Edit: 7

##   upload.php

##   editpics.php

##   editOnePic.php

##   include/picmgmt.inc.php

##   lang/english.php

##   formats_upload.php

##   formats_helper.php

## Included Files:

##   formats_upload/

##   images/formats_upload.png

##   js/fileprogress.js

##   js/handlers.js

##   swfupload.js

##   swfupload.queue.js

##   swfupload.swf

##   swfuploadbutton.swf

## License: http://opensource.org/licenses/gpl-license.php GNU General Public License v2

##############################################################

## Author Notes:

## This modification uses the http://swfupload.org/ upload script

##############################################################

## MOD History:
## 2009-06-30- version 1.1.1 bugfix to correct the slashes in the upload URL for Windows servers

## 2009-06-01- version 1.1.0 added unique filenames for uploads

## 2009-04-17- version 1.0.0

##############################################################

## Before Adding This MOD To Your Coppermine install, You Should Back Up All Files Related To This MOD

##############################################################



#

#-----[ IN COPPERMINE ]---------------------------------

#

   Log in as an administrator and go to Config. Expand the section

   "Custom fields for image description (leave blank if unused)" and

   enter a name in "Field 1 name" like "Other Formats". Save the new

   configuration



#

#-----[ UPLOAD ]----------------------------------------

#

   Upload all files in this package to you Coppermine root directory



#

#-----[ OPEN ]------------------------------------------

#

   upload.php



#

#-----[ FIND ]------------------------------------------

#

       // Create a text box.
   

   echo <<<EOT   



#

#-----[ BEFORE, ADD ]-----------------------------------

#

   // s garibaldi

   global $lang_upload_php;

   if ($text == $CONFIG['user_field1_name']) {

      $text = $text . ' &nbsp; &nbsp; <input type="button" onclick="window.open(\'formats_upload.php\',\'user1\',\'status=0,toolbar=0,location=0,menubar=0,height=300,width=420,resizable=1\')" value="' . $lang_upload_php['other_formats_button'] . '" class="button" /> &nbsp; ';

   }

   // e garibaldi



#

#-----[ OPEN ]------------------------------------------

#

   editpics.php



#

#-----[ FIND ]------------------------------------------

#

    echo <<<EOT

        <tr>

            <td class="tableb" style="white-space: nowrap;">

                        $text

        </td>

        <td width="100%" class="tableb" valign="top">

                <input type="text" style="width: {$field_width}%" name="$name" maxlength="$max_length" value="$value" class="textinput" />

                </td>

        </tr>



EOT;



#

#-----[ REPLACE WITH ]----------------------------------

#

   // s garibaldi

   global $CONFIG, $lang_editpics_php;

   if ($text == $CONFIG['user_field1_name']) {//ereg($CONFIG['user_field1_name'], $text)) {

      $text = $text . ' &nbsp; &nbsp; <input type="button" onclick="window.open(\'formats_upload.php\',\'' . $name . '\',\'status=0,toolbar=0,location=0,menubar=0,height=300,width=420,resizable=1\')" value="' . $lang_editpics_php['other_formats_button'] . '" class="button" /> &nbsp; ';

   }



    echo <<<EOT

        <tr>

            <td class="tableb" style="white-space: nowrap;">

                        $text

        </td>

        <td width="100%" class="tableb" valign="top">

                <input type="text" style="width: {$field_width}%" id="$name" name="$name" maxlength="$max_length" value="$value" class="textinput" />

                </td>

        </tr>



EOT;

   // e garibaldi



#

#-----[ OPEN ]------------------------------------------

#

   editOnePic.php



#

#-----[ FIND ]------------------------------------------

#

echo <<<EOT

        <tr>

            <td class="tableb" style="white-space: nowrap;">

                {$CONFIG['user_field1_name']}

                </td>

                <td width="100%" class="tableb" valign="top">

                                <input type="text" style="width: 100%" name="user1" maxlength="255" value="{$CURRENT_PIC['user1']}" class="textinput" />

                        </td>

        </tr>

EOT;   



#

#-----[ REPLACE WITH ]----------------------------------

#

// s garibaldi

global $lang_editpics_php;

$other_formats = ' &nbsp; &nbsp; <input type="button" onclick="window.open(\'formats_upload.php\',\'user1\',\'status=0,toolbar=0,location=0,menubar=0,height=300,width=420,resizable=1\')" value="' . $lang_editpics_php['other_formats_button'] . '" class="button" /> &nbsp; ';

echo <<<EOT

        <tr>

            <td class="tableb" style="white-space: nowrap;">

                {$CONFIG['user_field1_name']}{$other_formats}

                </td>

                <td width="100%" class="tableb" valign="top">

                                <input type="text" style="width: 100%" id="user1" name="user1" maxlength="255" value="{$CURRENT_PIC['user1']}" class="textinput" />

                        </td>

        </tr>

EOT;

// e garibaldi



#

#-----[ OPEN ]------------------------------------------

#

   include/picmgmt.inc.php



#

#-----[ FIND ]------------------------------------------

#

    $image = $CONFIG['fullpath'] . $filepath . $filename;

    $normal = $CONFIG['fullpath'] . $filepath . $CONFIG['normal_pfx'] . $filename;

    $thumb = $CONFIG['fullpath'] . $filepath . $CONFIG['thumb_pfx'] . $filename;



#

#-----[ AFTER, ADD ]------------------------------------

#

   // s garibaldi

   

   // ******************** //

   // *** START CONFIG *** //

   // ******************** //

   $user1_path = "/var/htdocs/cpg14x/formats_upload/";   // NOTE: even if you are using Windows, use forward slashes "/" for paths - e.g. C:/windows/

   $user1_url = "http://mycpgroot.com/formats_upload/";

   $extension = "zip";

   // ******************** //

   // **** END CONFIG **** //

   // ******************** //

   

   $user1_file = substr($filename, 0, strlen($filename)-3) . $extension;

   // check to see if user1 not set already and exists in the specified dir

   if(($user1 == '') && is_file($user1_path . $user1_file)) {

         $user1 = $user1_url . $user1_file;

   }

   // e garibaldi



#

#-----[ NOTE ]------------------------------------------

#

   Edit the lines the lines after START CONFIG and before END CONFIG,

   adjusting the path of the upload folder for the files. This folder should

   not be inside your Coppermine albums folder. Its permissions may also need

   to be adjusted to 777 to allow upload. You can also adjust the type of files

   that can be uploaded. By default only .zip files are allowed



#

#-----[ OPEN ]------------------------------------------

#

   lang/english.php



#

#-----[ FIND ]------------------------------------------

#

$log_date_fmt = '%B %d, %Y at %I:%M %p'; //cpg1.4



#

#-----[ AFTER, ADD ]------------------------------------

#

// s garibaldi

$other_formats_button="Add Formats";

// e garibaldi



#

#-----[ FIND ]------------------------------------------

#

  'forb_ext' => 'Forbidden file extension.',//cpg1.4



#

#-----[ AFTER, ADD ]------------------------------------

#

  'other_formats_button' => $other_formats_button,   // garibaldi



#

#-----[ FIND ]------------------------------------------

#

  'regenerate_dictionary' => 'Regenerate Dictionary', //cpg1.4



#

#-----[ AFTER, ADD ]------------------------------------

#

  'other_formats_button' => $other_formats_button,   // garibaldi



#

#-----[ NOTE ]------------------------------------------

#

   These same language modifications can be applied to other languages as well.

   Just replace the english text with your native language



#

#-----[ OPEN ]------------------------------------------

#

   formats_upload.php



#

#-----[ FIND ]------------------------------------------

#

   var upload_url = "http://mycpgroot.com/formats_upload/";



#

#-----[ EDIT ]------------------------------------------

#

   Change the URL to point to the formats_upload folder inside your Coppermine Root



#

#-----[ OPEN ]------------------------------------------

#

   formats_helper.php



#

#-----[ FIND ]------------------------------------------

#

   $save_path = "/var/htdocs/cpg14x/formats_upload/";



#

#-----[ EDIT ]------------------------------------------

#

   Edit the path to point to your system's path to the formats_upload folder. This

   looks like the above example on linux/unix servers and on Windows might look like

   C:\webserver\cpg14x\formats_upload



#

#-----[ SAVE/CLOSE ALL FILES ]--------------------------

#

# EoM

Joachim Müller

Thanks for your contribution. I have removed reference to the hotlinked images in your initial posting. We're not fond of hotlinking to external resources (and in fact the bbocde tag [ i m g ] has been deliberately disabled here) as per board rules. I have merged the hotlinked images into two actual files and attached them to your initial posting on this thread.

Garibaldi


zelal

Dear Garibaldi,

Thanks for your great effort.

I added this feature to my site.

But unfortunately, when a user upload a zip file which has the same name of a previously uploaded (say, by another user) file it replaces the previously uploaded file.

For example, a user named John has taken a photo of Alaska Mountain. He made a jpg version and a BMP version. He wanted to give the BMP file (within Zip) beside the JPG file. Accordingly he zipped it and named "mountain.zip" and then uploaded it using your feature.

After some days, another user named Allan also published his similar image (Himalayan or Alaska or etc. mountain) with zip file whose name is same as earlierly uploaded (by John) zip file i.e. mountain.zip.

Since the upload folder is also same (i.e. /formats_upload/) the upload immediately replaces the earlier one i.e. John's file will no longer exist.

Could you please fix this?

Thanks in advance.

Zelal

Dear Muller, I apology in advance if break the forum rule(s) by posting this in this thread. I searched to have the solution, but I could not find. May be, my search was not proper.

Garibaldi

Hi Zelal,

Good point, the zip filenames should be unique. I'll make an update and post it soon. Glad to hear that you like the MOD!

Garibaldi

Hi Zelal,

I've made the necessary changes tonight and tested it on my site. The modification now takes your uploaded file, e.g. myFile.zip, and adds a random number before the extension, like myFile1295.zip. This way, even identically selected files are made unique. I've updated the script with these changes in the first post of this thread. You just have to upload the formats_upload.php and formats_helper.php files after editing their settings as appropriate for your site

zelal

Hi Garibaldi,

Thank you so much for your nice work. I think many people will like it.

Regards.

Zelal

mushipkw

Shows me the error
Parse error: parse error in C:\wamp\www\include\picmgmt.inc.php on line 42

Im trying this on Wamp, My directory structure is C:\wamp\www\[All Coppermine files]\
Here's what I have done in picmgmt.inc.php

// s garibaldi
   
   // ******************** //
   // *** START CONFIG *** //
   // ******************** //
   $user1_path = "C:\wamp\www\formats_upload\";
   $user1_url = "http://localhost/formats_upload/";
   $extension = "zip";
   // ******************** //
   // **** END CONFIG **** //
   // ******************** //

What is the solution?

Joachim Müller

If you get a parse error you simply haven't followed the instructions to a T. Undo your edits and re-apply them thoroughly.

mushipkw

I have redone the whole procedur, still getting the same error. Have I inputted the correct values in picmgmt.inc.php

Garibaldi

It looks like an issue with Windows parsing the slashes as escape characters. Try replacing the double quotes in line 42 with single quotes. This will tell php to treat it completely as a string. If that doesn't work, for each slash "\", replace it with 3 slashes "\\\". I believe that will escape it correctly.


Joachim Müller

A slash actually looks like this: /
What you're refering to ( \ ) is actually a backslash.

Garibaldi

Sorry, yes 2 backslashes. I was thinking 3 from when I recently had to escape a backslash followed by a quote

mushipkw

Thanks guys got it working,  actually used front slashes instead of back slashes in the path.

Garibaldi

Great glad to hear it! It may be the case that although windows uses backslashes for paths, php replaces those with regular slashes for windows paths to avoid this problem of unintentional escape characters

Garibaldi

I added information about this issue to the package attached to the first post and the instructions in the second post

mushipkw

I would like to add more extensions i.e rar for supported upload. How can I do that?

Joachim Müller

How to add other file types (extensions) is beyond the scope of this mod, but has been explained often already. Please use the search. If you can't find good results after performing a thorough search start a thread of your own on the support board, providing the needed details.