forum.coppermine-gallery.net

No Support => Modifications/Add-Ons/Hacks => Mods: Uploading => Topic started by: klingsor on July 12, 2005, 06:42:40 pm

Title: A little functionality hack for batch upload
Post by: klingsor on July 12, 2005, 06:42:40 pm
Hi people,

Currently I'm finishing the setup of a small image bank. We upload the pics with the batch utility, using one folder per each image owner.

As some owners can have more of 5,000 pics, it's tiring to open the batch upload and wait until the page finishes to load, only to search at the bottom for, say 300 new pics.

For that reason I have made the following change to searchnew.php (1.3.3)

Now only shows the new pics and doesn't shows the previously uploaded pics. As I have saw some requests of people for this I decided to publish it here:

Search for function picrow:

Code: [Select]
function picrow($picfile, $picid, $albid)
{
    global $CONFIG, $expic_array;

    $encoded_picfile = base64_encode($picfile);
    $picname = $CONFIG['fullpath'] . $picfile;
    $pic_url = urlencode($picfile);
    $pic_fname = basename($picfile);
    $pic_dirname = dirname($picname);

    $thumb_file = dirname($picname) . '/' . $CONFIG['thumb_pfx'] . $pic_fname;
    if (file_exists($thumb_file)) {
        $thumb_info = getimagesize($picname);
        $thumb_size = compute_img_size($thumb_info[0], $thumb_info[1], 48);
        $img = '<img src="' . path2url($thumb_file) . '" ' . $thumb_size['geom'] . ' class="thumbnail" border="0" />';
    } elseif (is_image($picname)) {
        $img = '<img src="showthumb.php?picfile=' . $pic_url . '&size=48" class="thumbnail" border="0">';
    } else {
        $file['filepath'] = $pic_dirname.'/'; //substr($picname,0,strrpos($picname,'/'))
        $file['filename'] = $pic_fname;
        $filepathname = get_pic_url($file,'thumb');
        //$mime_content = get_type($picname);
        //$extension = file_exists("images/thumb_{$mime_content['extension']}.jpg") ? $mime_content['extension']:$mime_content['content'];
        //$img = '<img src="images/thumb_'.$extension.'.jpg" class="thumbnail" width="48" border="0">';
        $img = '<img src="'.$filepathname.'" class="thumbnail" width="48" border="0">';
    }

    if (filesize($picname) && is_readable($picname)) {
        //$fullimagesize = getimagesize($picname); COMMENTED OUT FOR VIDEO SUPPORT
        $winsizeX = ($fullimagesize[0] + 16);
        $winsizeY = ($fullimagesize[1] + 16);

        //$checked = isset($expic_array[$picfile]) || !$fullimagesize ? '' : 'checked';

        $checked = isset($expic_array[$picfile]) ? '' : 'checked';

        return <<<EOT
        <tr>
                <td class="tableb" valign="middle">
                        <input name="pics[]" id="picselector" type="checkbox" value="$picid" $checked />
                        <input name="album_lb_id_$picid" type="hidden" value="$albid" />
                        <input name="picfile_$picid" type="hidden" value="$encoded_picfile" />
                </td>
                <td class="tableb" valign="middle" width="100%">
                        <a href="javascript:;" onClick= "MM_openBrWindow('displayimage.php?&fullsize=1&picfile=$pic_url', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width=$winsizeX, height=$winsizeY')">$pic_fname</a>
                </td>
                <td class="tableb" valign="middle" align="center">
                        <a href="javascript:;" onClick= "MM_openBrWindow('displayimage.php?&fullsize=1&picfile=$pic_url', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width=$winsizeX, height=$winsizeY')"><img src="images/spacer.gif" width="1" height="48" alt="" border="0" />$img<br /></a>
                </td>
        </tr>
EOT;
    } else {
        $winsizeX = (300);
        $winsizeY = (300);
        return <<<EOT


Now replace with:


Code: [Select]
function picrow($picfile, $picid, $albid)
{
    global $CONFIG, $expic_array;

    $encoded_picfile = base64_encode($picfile);
    $picname = $CONFIG['fullpath'] . $picfile;
    $pic_url = urlencode($picfile);
    $pic_fname = basename($picfile);
    $pic_dirname = dirname($picname);

    $thumb_file = dirname($picname) . '/' . $CONFIG['thumb_pfx'] . $pic_fname;
    if (file_exists($thumb_file)) {
        $thumb_info = getimagesize($picname);
        $thumb_size = compute_img_size($thumb_info[0], $thumb_info[1], 48);
        $img = '<img src="' . path2url($thumb_file) . '" ' . $thumb_size['geom'] . ' class="thumbnail" border="0" />';
    } elseif (is_image($picname)) {
        $img = '<img src="showthumb.php?picfile=' . $pic_url . '&size=48" class="thumbnail" border="0">';
    } else {
        $file['filepath'] = $pic_dirname.'/'; //substr($picname,0,strrpos($picname,'/'))
        $file['filename'] = $pic_fname;
        $filepathname = get_pic_url($file,'thumb');
        //$mime_content = get_type($picname);
        //$extension = file_exists("images/thumb_{$mime_content['extension']}.jpg") ? $mime_content['extension']:$mime_content['content'];
        //$img = '<img src="images/thumb_'.$extension.'.jpg" class="thumbnail" width="48" border="0">';
        $img = '<img src="'.$filepathname.'" class="thumbnail" width="48" border="0">';
    }

    if (filesize($picname) && is_readable($picname)) {
        //$fullimagesize = getimagesize($picname); COMMENTED OUT FOR VIDEO SUPPORT
        $winsizeX = ($fullimagesize[0] + 16);
        $winsizeY = ($fullimagesize[1] + 16);

        //$checked = isset($expic_array[$picfile]) || !$fullimagesize ? '' : 'checked';

        $checked = isset($expic_array[$picfile]) ? '' : 'checked';

    if ($checked == 'checked'){
        return <<<EOT
        <tr>
                <td class="tableb" valign="middle">
                        <input name="pics[]" id="picselector" type="checkbox" value="$picid" $checked />
                        <input name="album_lb_id_$picid" type="hidden" value="$albid" />
                        <input name="picfile_$picid" type="hidden" value="$encoded_picfile" />
                </td>
                <td class="tableb" valign="middle" width="100%">
                        <a href="javascript:;" onClick= "MM_openBrWindow('displayimage.php?&fullsize=1&picfile=$pic_url', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width=$winsizeX, height=$winsizeY')">$pic_fname</a>
                </td>
                <td class="tableb" valign="middle" align="center">
                        <a href="javascript:;" onClick= "MM_openBrWindow('displayimage.php?&fullsize=1&picfile=$pic_url', 'ImageViewer', 'toolbar=yes, status=yes, resizable=yes, width=$winsizeX, height=$winsizeY')"><img src="images/spacer.gif" width="1" height="48" alt="" border="0" />$img<br /></a>
                </td>
        </tr>
EOT;
}
    } else {
        $winsizeX = (300);
        $winsizeY = (300);
        return <<<EOT



It uses the checked variable to decide if a picture has been uploaded (it must has a thumbnail)

I hope that it can be useful for some of you.

Regards,

Klingsor
Title: Re: A little functionality hack for batch upload
Post by: JasonB on August 07, 2005, 06:40:07 am
Nice!
Title: Re: A little functionality hack for batch upload
Post by: Hein Traag on August 08, 2005, 06:25:34 pm
I thank you. Just what i needed.

Just one question. Can you perhaps add a option one the searchnew page which you can select if you do wish to see the entire list ?
Title: Re: A little functionality hack for batch upload
Post by: tricoven on August 11, 2005, 05:20:51 pm
omg this hack f*cking rocks!!!
Title: Re: A little functionality hack for batch upload
Post by: Yukino on September 15, 2005, 05:56:21 am
just so you know i run version 1.4.1 and i just applied this hack and it works with it great. 

u r tha best!
Title: Re: A little functionality hack for batch upload
Post by: Tranz on September 15, 2005, 07:11:44 am
just so you know i run version 1.4.1 and i just applied this hack and it works with it great.

u r tha best!
Thank you for letting us know.
Title: Re: A little functionality hack for batch upload
Post by: falarious on December 28, 2005, 12:10:49 am
HOLY MOTHER and FATHERS!!!!  :o

This is the best hack in the world!!  ;D ;D :D
Title: Re: A little functionality hack for batch upload
Post by: tmpicture on February 09, 2006, 01:00:09 am
Hi,

Has anybody improved or extended this hack? And what about that...
Quote
Just one question. Can you perhaps add a option one the searchnew page which you can select if you do wish to see the entire list ?


Thanks, Thomas
Title: Re: A little functionality hack for batch upload
Post by: n3n on May 26, 2006, 03:56:52 pm
Very nice ! Tnx for the work.
Title: Re: A little functionality hack for batch upload
Post by: wirewolf on June 15, 2006, 01:19:11 am
It's the simple things that make one happy!  :) Just tried it on cpg version: 1.4.8. Works like a charm!
Thank you Klingsor.
John
Title: Re: A little functionality hack for batch upload
Post by: lamama on November 18, 2006, 10:28:31 am
This is a fine piece of code.

I expierenced a lot of "out of memory"-errors (leading to Apace Error 503's) while batch-adding ca. 190 big-sized pics (up to 2 megapixels, 150-450 kb per pic) to an album that already contained 400 pics.

With this mod, the batch-add worked fine and used only half of the servers memory while it was running (compared to the regular code that just stopped working during batch-add).



Title: Re: A little functionality hack for batch upload
Post by: cavok on November 09, 2010, 04:42:50 pm
Hello.
Is it possible to do the same for 1.5.8 version ?
Title: Re: A little functionality hack for batch upload
Post by: Joachim Müller on November 10, 2010, 08:43:02 am
Don't ask for other versions (http://forum.coppermine-gallery.net/index.php/topic,24540.0.html). Locking.