#! /usr/bin/perl -- -*-perl-*->
# A perl cgi program to display an HTML table index of photos in a directory.
# Copy this perl script to your public_html/cgi-bin directory. $RelativeDir refers to directories under public_html/.
# Note: When this script executes, the home directory ~ is cgi-bin/.
# Note: If you're having trouble, change "cgiwrap" to "cgiwrapd" to show debug info.
#
# SSI usage example: (Copy and remove '#' at the beginning of the line. Subsitute your username for USERNAME below.
# Be sure to name your file with the .shtml extension for server side parsing.)
#
#<HTML>
#<HEAD>
#   <TITLE>Family Photos</TITLE>
#   <META HTTP-EQUIV="Bulletin-Text" CONTENT="Family Photos">
#   <META HTTP-EQUIV="Bulletin-Date" CONTENT="Sat, 23-Aug-00 19:23:53">
#   <META NAME="Description" CONTENT="My Family Photos">
#   <META NAME="KeyWords" CONTENT="MyFamily, Photographs">
#</HEAD>
#
#<BODY TEXT="#400040" BGCOLOR="#FFFFFF" LINK="#0000D0" VLINK="#0000D0" ALINK="#FF0080">
#
#<!-- #include virtual="/cgi-bin/cgiwrap/USERNAME/photoindex.pl?reldir=family&xtable=4" -->
#
#</BODY>
#</HTML>
#
 
use CGI qw(param);

$RelativeDir=   param("reldir");
$Xtable=        (param("xtable")==undef)  ?   4 : param("xtable");
$Xwidth=        (param("xwidth")==undef)  ? 600 : param("xwidth");
$Xcell=         (param("xcell")== undef)  ? 150 : param("xcell");

$PhotoDir="../$RelativeDir";
print "Content-type: text/html\n\n";

opendir(PHOTODIR, "$PhotoDir") || die "Error: no directory $PhotoDir $!";
while ($FileName= readdir(PHOTODIR))
 {
 if ($FileName=~ /.*\.(jpg|JPG|gif|GIF)/)
     {
     $i++; 
     if ($i==1) {print "<table width=$Xwidth align=center border=0 cellpadding=2>\n  <tr>\n";}
     print "    <td  align=center><a href=$RelativeDir/$FileName><img src=$RelativeDir/$FileName alt=$FileName border=0 width=$Xcell></a></td>\n";
     if ($i % $Xtable == 0) {print "  </tr>\n  <tr>\n";}
     }
 }
print "  </tr>\n</table>\n";
closedir (PHOTODIR);

exit 0; # End Program.

