Wrapped in gaffa

Programming, Art, Music, Philosophy, Politics

Downloading galleries with Zenphoto

with 16 comments

Last weekend I had a Christmas Party or what you call it in english – it is basically a danish tradition where you drink a lot of schnapps, with marinated herring and anything made from pigs on rye bread. A great one also has warm food, but mine didn’t.. I think it all evolves around the schnapps and beer, the rest is just fittings.

Anyway I took a lot of pictures with my quite expensive digital camera before I got too drunk.. and decided to hide it from myself. Digital pictures is no fun unless you can share peoples embarrassing moments online, so I installed Zenphoto on my Dreamhost account. Worked like a charm, but soon people started requesting an archived download of the entire gallery. I did a little search and found out that Zenphoto already had that function printAlbumZip and I just had to add it to the Template which was as easy (even for a PHP virgin like me) as adding <?php if (function_exists(‘printAlbumZip’)) { printAlbumZip(); } ?> somewhere appropiate in the template and turned on persistent archive in Zenphoto, so that the gallery would not be archived more than once. Storage space was not a big issue, but apparently RAM was – I kept getting errors because memory ran out. I took a look at createAlbumZip and found that it was sending the file by using readfile which puts the entire ~500MB into RAM before sending it. I did a small patch to cache and send chunks of 16MB at a time in createAlbumZip, it’s not a pretty patch, but I guess simply using readfile isn’t either.

I replaced this code in zp-core/functions.php:
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . urlencode($album) . '.zip"');
echo file_get_contents($dest);

With this:
$buf_size = 1024*16;
$file = fopen($dest, "r");
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . urlencode($album) . '.zip"');
header('Content-Length: ' . filesize($dest));
print fread($file, $buf_size);

Link to gallery


Written by gaffa

2008-12-07 at 17:12

Posted in Programming, Software

Tagged with

16 Responses

Subscribe to comments with RSS.

  1. Excellent code thanks for that fixed up downloading albums on my dreamhost zenphoto installation


    2009-12-31 at 05:16

  2. Can you explain exactly how you get the link to the zip file to show up on the album page? I cannot get this working in my environment.


    2010-02-05 at 18:54

  3. In zenphoto/themes/your_theme/album.php (replace your_theme with the folder of your theme) you insert this line of PHP where you want the link to be displayed:

    <?php if (function_exists(‘printAlbumZip’)) { printAlbumZip(); } ?>

    If this doesn’t display a link, printAlbumZip might not be supported in your Zenphoto installation.


    2010-02-06 at 18:31

  4. Thanks, I got this working. I was copying what you had published above and it pasted the incorrect character ‘ in the php file. Once I corrected all the ‘ it worked.

    It also looks like they have resolved the memory issue in v1.2.8 with the following code:

    * Processes a file for createAlbumZip
    * @param string $dest the source [sic] to process
    function printLargeFileContents($dest) {
    $total = filesize($dest);
    $blocksize = (2 << 20); //2M chunks
    $sent = 0;
    $handle = fopen($dest, "r");
    while ($sent < $total) {
    echo fread($handle, $blocksize);
    $sent += $blocksize;


    2010-02-09 at 19:19

    • Thank you for updating me on ZenPhoto, Jester.


      2010-04-24 at 11:12

  5. I also think hence, perfectly written post!

    neue um zu


    2012-09-14 at 06:24

  6. And just as I mentioned above that you simply came across
    a large number of distinctive types of medicines, but
    still you’re in problems. Further information can be obtained by contacting the Washington Institute of Natural Medicine at (202) 237-7681. It is also possible that if CLASS recipients are eventually enrolled in AHCCCS (Arizona’s Medicaid program), AHCCCS will
    benefit financially by receiving a share of the cash payment
    made by the CLASS program. Michael has done his stint and
    it should be left to rest. Members of the press and/or other interested
    parties may obtain more information about this practice and/or the content of this press release by contacting the
    following: Fayette Chiropractic Center Dr.


    2013-03-07 at 05:41

  7. Hi there, just wanted to mention, I liked this post.
    It was funny. Keep on posting!

  8. This is exactly the fourth post, of your site I actually browsed.
    Although I enjoy this 1, “Downloading galleries with Zenphoto | Wrapped in gaffa” the very best.
    Regards -Meghan


    2013-07-01 at 18:55

  9. Remarkable! Its truly awesome piece of writing, I have got much clear idea about from this article.

  10. What’s up friends, its wonderful post about tutoringand completely defined, keep it up all the time.

  11. Nowadays one should use the plug-in downloadList and the printDownloadLinkAlbumZip function. As far as I can tell this streams the ZIP-file too, at least the download started imeaditly and there is no high memory use…


    2013-11-24 at 00:16

  12. super site de e cigarette en france http://www.ecigarette-board.com


    2014-01-23 at 04:54

  13. Excellent goods from you, man. I’ve be mindful your stuff prior to and you
    are just extremely great. I really like what you’ve obtained here, really like what you’re stating and the best way wherein you assert it.
    You are making itt entertaining andd you continue to take care off tto
    keep it smart. I cant waiot to read far more from you.
    This is really a great website.


    2014-03-27 at 01:24

  14. An outstanding share! I’ve just forwarded this onto a
    colleague who had been conducting a little research
    on this. And he in fact ordered me dinner due to
    the fact that I discovered it for him… lol. So allow me to reword this….
    Thanks for the meal!! But yeah, thanx for spending time to talk about this issue
    here on your web page.

  15. Somebοdy essentially lend а ɦand to mɑke severely
    posts Ӏ’d state. This is thе first time I frequented ʏߋur website paցe and tto this poіnt?
    Ӏ surprised with the research you made to crewte tuis
    рarticular рut ᥙp amazing. Great task!


    2016-06-05 at 10:56

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: