#!/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 sla
+sh
my $root = "../../httpdocs/photoalbum/"; #Filesystem - needs
+ trailing slash
my $template = "template.html"; #file (in photo director
+y)
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[<a href="] . $cgi . q[?">click here to view a different
+album</a>];
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[<img src="] . $url . $_ . q[" alt="" border="0">];
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__
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/
+/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>photo album</title>
<style>
<!--
.small { font-size: .75em; }
-->
</style>
</head>
<body bgcolor="#FFFFFF">
<h1><TMPL_VAR NAME="DIR"></h1>
<TMPL_IF NAME="SHOWLINK">
<p class="small">Link directly to this album:<br /><TMPL_VAR NAME=
+"DLINK"></p>
</TMPL_IF>
<div align="center" class="small"><TMPL_VAR NAME="RLINK"></div>
<TMPL_LOOP NAME="PICTURES">
<p align="center"><TMPL_VAR NAME="TAG"></p>
</TMPL_LOOP>
</body>
</html>
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|