Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Quick-n-dirty Photo Album

by newrisedesigns (Curate)
on Feb 14, 2003 at 18:44 UTC ( #235367=sourcecode: print w/replies, xml ) Need Help??
Category: CGI Programming
Author/Contact Info John J Reiser
comments encouraged: /msg me or reply
Description: An online photo album that's easy to set up and use. Nothing elaborate, just a simple way to display the images (JPGs) in a directory on your website. Feel free to download, use, and modify as you see fit.
#!/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/";    #CGI Location
my $url        = "/photoalbum/";            #IMG SRC - needs trailing 
my $server    = '';    #Server - NO trailing sla
my $root    = "../../httpdocs/photoalbum/";        #Filesystem - needs
+ trailing slash
my $template    = "template.html";            #file (in photo director

my $q = CGI->new();
my $t = HTML::Template->new(filename => $root . $template);

my $album = $q->param('album') || '';
if($album =~ /(\w+)/){
    $album = $1;
    $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();


my $rlink = q[<a href="] . $cgi . q[?">click here to view a different 
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));

my @tags;

    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;


opendir($fh, '.');
my @files = sort grep((-d $_) && ($_ !~ /\./), readdir($fh));

return @files;


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/

<title>photo album</title>
.small { font-size: .75em; }

<body bgcolor="#FFFFFF">
<h1><TMPL_VAR NAME="DIR"></h1>
    <p class="small">Link directly to this album:<br /><TMPL_VAR NAME=
    <div align="center" class="small"><TMPL_VAR NAME="RLINK"></div>
        <p align="center"><TMPL_VAR NAME="TAG"></p> 
Replies are listed 'Best First'.
Re: Quick-n-dirty Photo Album
by PodMaster (Abbot) on Feb 15, 2003 at 17:24 UTC
    Here's a suggestion, use File::Spec
    perl -MFile::Spec -e " die File::Spec->catfile( qw[ foo /bar baz ], sh +ift ) " bar

    update: and use URI::URL; ;)

    perl -MURI::URL -e " die URI::URL->new(q[foo/bar/baz], q[ +m/])->canonical; " perl -MURI::URL -e " die URI::URL->new(q[foo/bar/baz], q[ +m/])->abs; "

    update: Also, it's nice that you used HTML::Template, but you might consider a lighter weight alternative to CGI (CGI::Simple) since you're not using CGI to generate x?html.

    MJD says you can't just make shit up and expect the computer to know what you mean, retardo!
    I run a Win32 PPM repository for perl 5.6x+5.8x. I take requests.
    ** The Third rule of perl club is a statement of fact: pod is sexy.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: sourcecode [id://235367]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2021-01-20 11:27 GMT
Find Nodes?
    Voting Booth?