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

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]

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.

mushipkw

[quote

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

   // *** 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 **** //

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

   

#-----[ 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

#

[/quote]

What Im asking about is how to add support for rar in this section?

Joachim Müller

Do as I suggested:
Quote from: Joachim Müller on July 23, 2009, 05:46:45 PMstart a thread of your own on the support board, providing the needed details.
Hint: what a needed detail is can be found out by reading the board rules.

Joachim

P.S. You should learn how to quote using bbcode

Garibaldi

Sorry for my late response. I've created a support topic for this modification in the support forum. Here is a link:
http://forum.coppermine-gallery.net/index.php/topic,60768.0.html

I have posted a response to your question about alternate filetypes there.

Thanks,

Garibaldi

Garibaldi

I'm releasing an update that includes support for deleting the uploaded file when you delete a picture. To upgrade, simply follow these instructions:
#

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

#

delete.php



#

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

#

if (!is_writable($dir)) cpg_die(CRITICAL_ERROR, sprintf($lang_errors['directory_ro'], htmlspecialchars($dir)), __FILE__, __LINE__);



#

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

#

    // start garibaldi
    $g_query = "SELECT user1 FROM {$CONFIG['TABLE_PICTURES']} WHERE pid='$pid'";
    $g_result = cpg_db_query($g_query);
    $g_user2 = mysql_fetch_array($g_result);
    foreach($g_user2 as $key => $value) {
if (strpos($value, "http") === false) {
} else {
// if its the url, grab it and cut off the part we don't want and put on the server path
$path = str_replace($CONFIG['ecards_more_pic_target'], "", $value);
}
    }
    if (is_file($path)) {
    unlink($path);
    }
    // end garibaldi


You can download the full installation for this new version in the first post of this topic

mushipkw

I tested it on my local server & website but its not working.

Garibaldi

Can you find an image that you want to delete and edit it in Coppermine. Check the value of the Custom User 1 Field and send it back to me. It should be of the form http://yourcpg.com/formats_upload/myzip4895.zip . If that is the case, this script then cuts off the URL making it formats_upload/myzip4895.zip and then removes it. Make sure your upload directory (formats_upload) is 777.

mushipkw


Garibaldi

I'll put some debug code together for you and have it up soon for you to test

Garibaldi

Sorry for the late reply. Replace the code I posted a couple posts up with this in delete.php:
    // start garibaldi
    $g_query = "SELECT user1 FROM {$CONFIG['TABLE_PICTURES']} WHERE pid='$pid'";
    $g_result = cpg_db_query($g_query);
    $g_user2 = mysql_fetch_array($g_result);
    foreach($g_user2 as $key => $value) {
if (strpos($value, "http") === false) {
} else {
// if its the url, grab it and cut off the part we don't want and put on the server path
$path = str_replace($CONFIG['ecards_more_pic_target'], "", $value);
}
    }
   
    echo "Query: " . $g_query . "<br>Result: " . $g_result . "<br>User 1 Value: " . $g_user2 . "<br>Path: " . $path . "<br>";
   
    if (is_file($path)) {
    echo "Deleting: " . unlink($path);
    }
    // end garibaldi


Then, after you delete a photo on the page where it shows the green or red images for successful or failed deletions, it will print out some information above the table in this format:
QuoteQuery: SELECT user1 FROM xxx_pictures WHERE pid='xx'
Result: Resource id #xx
User 1 Value: Array
Path: formats_upload/xxxxxx-23492.zip
Deleting: 1
Please copy and paste it back here and I'll take a look at it.

mushipkw

Here's what it looks like on my local server.

QuoteQuery: SELECT user1 FROM s2u2c_pictures WHERE pid='13'
Result: Resource id #57
User 1 Value: Array
Path: http://localhost/formats_upload/BetterBlogRoll5563.zip

Garibaldi

Ah yes, I see the problem. It appears that the ecards_more_pic_target field in your database is not setup correctly. It should contain the URL of your coppermine site (with trailing slash). If you can correct this in your configuration, you should be able to use the code as is. Otherwise, find:
$CONFIG['ecards_more_pic_target']
and replace it with (in this case):
http://localhost/

After doing this, give it a try again and see if it works

mushipkw


Garibaldi


SpectroPro

Something I noticed...and this is working ALMOST perfectly on my site.  But, when you delete a file from the EDIT FILES part of the albums list...the picture will be deleted..but the files are not.  The only way for them to be deleted currently, is by doing the delete from the lone file (picture) screen. 

I hope this makes sense...  If not, I can maybe explain better and show pictures of what I mean.

Can this be fixed so that no matter where you delete the picture from, it deletes the associated file(s)?

- Greg

mushipkw

Correct, I would like to add on that,
Also when we edit file properties & upload another file from there, the previous file doesn't gets deleted.

SpectroPro

Quote from: mushipkw on September 07, 2009, 02:07:51 PM
Correct, I would like to add on that,
Also when we edit file properties & upload another file from there, the previous file doesn't gets deleted.

I just noticed this as well.  Can't update or change the file associated with the pic by just uploading a new file.  Maybe a new button, 'Update File'??  This would simply delete the old and put in the new.

Also, curious as to why when you upload, the window wording shows File Queue....???  I can select multiple files, but it will only ever allow one file to upload at a time.  Then you select another.  Thus, no queue.   Just curious about this...am I missing a way to upload 2 or more files at once for a pic?

I am actually wanting, for my use of this....to have more than one pic per file more than one file per pic.  But I am very happy to have this as it is currently, because it will allow me to open my site (graphic object site...for 3d objects for use in games, sims, movies, etc...)  I can imagine it will only get better and more feature enhanced in the future.. 

Thank you very much for this add-on (mod)!!!!!!

- Greg

mushipkw

I am trying to tweak a function that adds a random number at the end of filename. I tried to change it that it only adds the random number when a file already exists with the same name.

This is what I have tried but it doesn't work. Also the popup windows remains open when clicked Done & loads the main page.
function finish() {
var upload_url = "http://localhost/formats_upload/";
var filename = str_replace(" ", "%20", document.getElementById("fileNAME").value);

if (file_exists(upload_url + filename)) {
window.opener.document.getElementById(window.name).value = upload_url + substr(filename, 0, strlen(filename)-4) + document.getElementById("rand").value + substr(filename, strlen(filename)-4);
} else {
window.opener.document.getElementById(window.name).value = upload_url + substr(filename, 0, strlen(filename)-4) + substr(filename, strlen(filename)-4);
}
close();
}


How can i get it to work?

Garibaldi

What does this random number addition do that is different from how the modification already adds a random number to the end of the file string?

mushipkw

NO, NO you are getting it wrong.
I want that a random number is only added when a file exists with the same name, else the file name remains the same as uploaded.
But I can't seem to figure it out with my code.

Garibaldi

Try finding this code in formats_helper.php:
// Make it unique
$file_name = substr($file_name, 0, strlen($file_name)-4) . $_GET['rand'] . substr($file_name, strlen($file_name)-4);


Replace it with this:
// test if it already exists
if (exists($file_name)) {
// Make it unique
$file_name = substr($file_name, 0, strlen($file_name)-4) . $_GET['rand'] . substr($file_name, strlen($file_name)-4);
}

See if that works.