#!/usr/bin/perl -w
## Quick and Dirty Online Photo Album
## by John J Reiser (newrisedesigns)
use strict;
use CGI;
use HTML::Template;
my $cgi = "/cgi-bin/album.pl"; #CGI Location
my $url = "/photoalbum/"; #IMG SRC - needs trailing slash
my $server = 'http://www.website.tld'; #Server - NO trailing slash
my $root = "../../httpdocs/photoalbum/"; #Filesystem - needs trailing slash
my $template = "template.html"; #file (in photo directory)
my $q = CGI->new();
my $t = HTML::Template->new(filename => $root . $template);
my $album = $q->param('album') || '';
if($album =~ /(\w+)/){
$album = $1;
}
else{
$album = '';
}
if($album eq ''){
my @dir = finddir($root);
my $form;
$form = $q->start_form(-method=>"POST");
$form .= $q->p($q->popup_menu(-name=>"album", -value=>[@dir]));
$form .= $q->p($q->submit());
$form .= $q->end_form;
$t->param(DIR => "Choose an album to view");
$t->param(RLINK => $form);
print $q->header();
print $t->output();
}
else{
my $rlink = q[click here to view a different album];
my $dlink = $server . $cgi . '?album=' . $album;
$album .= '/';
$url .= $album;
$t->param(DIR => $album);
$t->param(SHOWLINK => 1);
$t->param(RLINK => $rlink);
$t->param(DLINK => $dlink);
my $fh;
opendir($fh, $root . $album) or die("Cannot open $root$album $!");
my @files = sort grep(/\.jpg$/, readdir($fh));
closedir($fh);
my @tags;
foreach(@files){
my $tag = q[];
push(@tags, {'TAG' => $tag});
}
$t->param(PICTURES => \@tags);
print $q->header();
print $t->output();
}
sub finddir{
my $dir = shift;
my $fh;
chdir($dir);
opendir($fh, '.');
my @files = sort grep((-d $_) && ($_ !~ /\./), readdir($fh));
closedir($fh);
return @files;
}
__END__
Link directly to this album: