Feature-request: Download complete set as zip

Hi zenformuns :)

i have to admit, i am very sorry for my bad english ;)

I think it would be nice, to be able to download a whole Gallery as a zipfile. Gallery2 has such a feauture and it is used very often for our photo galleries.

Maybe it is not very difficult to add; a zip on the fly for a complete folder would be enough. A Download basket is - imho - oversized, a simple click to get a whole folder would be a cool hack :-)

My PHP skills are as bad as my english, otherwise i would do such a hack myself ;-)

Comments

  • trisweb Administrator
    Excellent idea! Submit it as an enhancement in the bugtracker :-)
  • I got some code, if you would like to try it. It does use a created zip class that someone made, I am not sure how you feel about using other peoples work in your own work.
  • weed Member
    sound cool - where to find it? :)
  • trisweb Administrator
    Is the Zip class licensed under the GPL? Then it's ok!
  • http://www.devco.net/code/zipfile.inc.txt

    there is the code.

    Here is what I did

    `function getAlbumListForZip(){

    $albumList = mysql_query("SELECT `title`, `folder` FROM ".prefix("albums")."") or die(mysql_error());

    echo '';

    echo '


    ';

    echo 'Album to create ZIP File From: ';

    while ($albums = mysql_fetch_array($albumList)){

    echo ''.$albums['title'].'';

    echo "r";

    }

    echo '';

    echo "r
    Include Cache";

    echo "r
    ";

    echo '';

    }`

    then I did this

    `}else if ($page == "createzip"){

    require_once('class-zipfile.php');

    if (isset($_POST['all'])){

    $albumList = mysql_query("SELECT `folder` FROM ".prefix("albums")."") or die(mysql_error());

    while($albums = mysql_fetch_array($albumList)){

    $zipfile = new zipfile();

    $zipfile -> add_dir("/");

    // add the binary data stored in the string 'filedata'

    if ($handle = opendir('../albums/'.$albums['folder'].'/')) {

    while (false !== ($file = readdir($handle))) {

    if ($file != "." && $file != "..") {

    $zipfile -> add_file($file, $file);

    echo $file." was added to the zip for ".$albums['folder']."n
    ";

    }

    }

    closedir($handle);

    if (file_exists($zipfilename)){

    unset($zipfilename);

    }

    $filename = "albums/".$albums['folder']."/pictures.zip";

    $albumName = $albums['folder'];

    $fd = fopen ('../'.$filename, "wb");

    $out = fwrite ($fd, $zipfile -> file());

    fclose ($fd);

    $updateZip = mysql_query("UPDATE ".prefix("albums")." SET `zipFile` = '$filename' WHERE `folder` = '".$albums['folder']."'") or die(mysql_error());

    }

    }

    }


    if (isset($_POST['submit'])){

    //print_r($_POST);

    $zipfile = new zipfile();

    $zipfile -> add_dir("/");

    // add the binary data stored in the string 'filedata'

    if ($handle = opendir('../albums/'.$_POST['albumName'].'/')) {

    while (false !== ($file = readdir($handle))) {

    if ($file != "." && $file != "..") {

    $zipfile -> add_file($file, $file);

    echo $file." was added to the zipn";

    }

    }

    closedir($handle);

    }

    if (isset($_POST['thumbnail'])){

    if ($handle = opendir('../cache/'.$_POST['albumName'].'/')) {

    while (false !== ($file = readdir($handle))) {

    if ($file != "." && $file != "..") {

    $zipfile -> add_file($file, $file);

    echo $file." was added to the zipn";

    }

    }

    closedir($handle);

    }

    }

    if (file_exists($zipfilename)){

    unset($zipfilename);

    }

    $filename = "albums/".$_POST['albumName']."/pictures.zip";

    $albumName = $_POST['albumName'];

    $fd = fopen ('../'.$filename, "wb");

    $out = fwrite ($fd, $zipfile -> file());

    fclose ($fd);

    $updateZip = mysql_query("UPDATE ".prefix("albums")." SET `zipFile` = '$filename' WHERE `folder` = '".$_POST['albumName']."'") or die(mysql_error());

    //echo $updateZip;

    }`

    If you need help, i can explain

  • sorry for the double post, i added a table in the albums table called zipFile, its varchar 50. there is probably a better way to do that but.... then in album.php (under theme)

    `<?php<br />
    $album = mysql_query("SELECT `zipFile` FROM ".prefix("albums")." WHERE `title` = '".getAlbumTitle()."'") or die(mysql_error());

    $zipFile = mysql_fetch_array($album);

    if ($zipFile[0] != ''){

    echo 'Download Images in .zip format Here';

    }

    ?>`

    here are the order of the files
    first block of code = admin-functions.php
    second block of code = admin.php
    add tab to the menu
    then this past code add to the bottom of album.php right above the </div><div id="credit">
  • I was interested in this feature as well, so I decided to give it a try. The code given above didn't appeal to me, so I did something a little different. I'm not caching the zipfile nor am I making any trips to the database.

    Changes:
    * index.php: 2 lines
    * functions.php: 1 function to zip the album, ~18 lines
    * template-functions.php: 1 function to display a link, ~5 lines
    * New Class: zipfile, Location: zen/zip/zipfile.php

    You can see the example at: http://mu.thenullpointer.net

    Steps:
    1. Visit a specific album
    2. Under the pictures (above the geocoded map, if there is one) there is a link "Download a zip file of this album"
    3. Click link to download the zipfile.
  • @ mannkind: Your changes sounds very easy to do. Is it possible to get your changes?
  • Well, I would be willing to provide the changes I made. It would be provided as-is without warranty. ;)
  • I need no warranty ;-) Thanks for sharing!
  • @mannkind: Did you upload some files anywhere? It would be very nice to have this feature.
  • @lordcoffee

    I apologize for not responding sooner.

    The patch is at http://www.zenphoto.org/trac/wiki/ZenphotoHacks#AlbumZip

    Hopefully that'll work for you. Works for me :) haha
  • @mannkind: Thanks one more time! I have a little problem with that "patch-thing". I've saved the code in a "zp108_zip.diff"-file. I can upload it via ftp into my zen folder. But how do "run patch -p1 < zp108_zip.diff"??? Sorry for noob-questions :-)
  • dwn Member
    @lordcoffe: that command will make patch to your zenphoto installation according to zp108_zip.diff file. What you need is to have some kind of SSH or TELNET access to your server and run that command in shell. If you can't do this, than let me know and i will upload modified files (for latest SVN) somewhere for you.

    @mannkind: i am using latest SVN code and patching failed on it. so i did it manually, i can give you output of it, if you want. but i don't have it right now with me. so let me know. everything else works fine - thanks for sharing the code;)
  • @lordcoffee, @dwn

    Well there I go, assuming things. You'd think I'd know better.

    1. I assumed that lordcoffee would have access to the patch command in some way
    2. I assumed that patching against the latest release would be better than patching against the SVN (although that is where I did my original code at -- I just ported it to the release code).

    *sigh*

    I apologize lordcoffee and dwn.
  • is there a plugin for this? couldn't find anything. i would like to integrate this download function.
  • i am using latest SVN code and patching failed on it. so i did it manually, i can give you output of it, if you want. but i don't have it right now with me. so let me know.

    <URLs removed by moderator>
  • acrylian Administrator, Developer
    @xemino: You will have to add the function `printAlbumZip()` to your theme's album.php or image.php
Sign In or Register to comment.