]> mj.ucw.cz Git - gallery.git/blob - gal/UCW/Gallery/Archive.pm
gal-mj-digikam imports GPS coordinates
[gallery.git] / gal / UCW / Gallery / Archive.pm
1 # Simple Photo Gallery: Archiving
2 # (c) 2003--2012 Martin Mares <mj@ucw.cz>
3
4 package UCW::Gallery::Archive;
5
6 use strict;
7 use warnings;
8
9 use Archive::Zip;
10 use File::Spec;
11 use UCW::CGI;
12
13 sub send_archive($$) {
14         my ($gal, $meta) = @_;
15
16         if (!$gal->get('WebAllowArchives')) {
17                 UCW::CGI::http_error('403 Archiving forbidden by server configuration');
18                 return;
19         }
20
21         my $zip = Archive::Zip->new;
22         my $cnt = 0;
23         for my $id (@{$meta->{sequence}}) {
24                 $zip->addFile(File::Spec->catfile($gal->get('PhotoDir'), "$id.jpg"), sprintf("%03d.jpg", $cnt)) or die;
25                 $cnt++;
26         }
27
28         print "Content-type: application/zip\n";
29         print "Content-Disposition: attachment; filename=gallery.zip\n";
30         print "\n";
31         $zip->writeToFileHandle(\*STDOUT, 0);
32 }
33
34 42;