]> mj.ucw.cz Git - gallery.git/blob - lib/UCW/Gallery/Archive.pm
0acfa7b56e2cdcd176361dadfbc065895687a984
[gallery.git] / lib / 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 common::sense;
7
8 use Archive::Zip;
9 use File::Spec;
10 use UCW::CGI;
11
12 sub send_archive($$) {
13         my ($gal, $meta) = @_;
14
15         if (!$gal->get('WebAllowArchives')) {
16                 UCW::CGI::http_error('403 Archiving forbidden by server configuration');
17                 return;
18         }
19
20         my $zip = Archive::Zip->new;
21         my $cnt = 0;
22         for my $id (@{$meta->{sequence}}) {
23                 $zip->addFile(File::Spec->catfile($gal->get('PhotoDir'), "$id.jpg"), sprintf("%03d.jpg", $cnt)) or die;
24                 $cnt++;
25         }
26
27         print "Content-type: application/zip\n";
28         print "Content-Disposition: attachment; filename=gallery.zip\n";
29         print "\n";
30         $zip->writeToFileHandle(\*STDOUT, 0);
31 }
32
33 42;