#!/usr/local/bin/perl
use File::Basename;
# *********************************************************************** #
# * * #
# * Copyright (c) 1996-1999 Scott Crevier * #
# * All Rights Reserved Worldwide * #
# * * #
# * This program product material is the property of Scott Crevier. * #
# * This program may be used and modified by anyone free of charge, * #
# * as long as this copyright notice remains in tact. By using this * #
# * code, you agree to indemnify Scott Crevier from any liability * #
# * that might arise from its use. * #
# * * #
# * scott@crevier.org - Scott M. Crevier - www.crevier.org * #
# *********************************************************************** #
# * smcImages v2.0 21-Dec-1998 * #
# * * #
# * This script provides a visual listing of your image directories. * #
# * * #
# * Put this script in your cgi-bin directory. Create an HTML file in * #
# * each of your image directories called 'ndx.shtml'. The contents * #
# * should look like this: * #
# * * #
# * * #
# * * #
# * * #
# * * #
# *********************************************************************** #
$foldericon = '/icons/folder.gif'; # you can change this
$indexfilename = $ENV{'DOCUMENT_NAME'};
$documentdir = dirname($ENV{'DOCUMENT_URI'});
$imgdir = $ENV{'DOCUMENT_ROOT'} . $documentdir;
# *********************************************************************** #
# * Go to the image directory and get a directory listing. * #
# *********************************************************************** #
chdir($imgdir);
opendir(DIR,'.') or die "Can't open $imgdir";
@filenames = grep !/^\./, readdir(DIR);
closedir(DIR);
# *********************************************************************** #
# * Count the images and total bytes used. * #
# *********************************************************************** #
$filecount = 0;
$dircount = 0;
$bytes = 0;
for (@filenames) {
if (-d) { $dircount++; next; }
if ((/\.gif$|\.jpg$/) && ($size = -s)) {
$filecount++;
$bytes += $size;
}
}
$bytes = &commas($bytes);
$file_string = ($filecount == 1) ? "image" : "images";
$dir_string = ($dircount == 1) ? "directory" : "directories";
# *********************************************************************** #
# * Print the HTML page. * #
# *********************************************************************** #
print "Content-type: text/html", "\n\n";
&printTop;
&printDirectories;
&printImages;
&printBottom;
exit(0);
# *********************************************************************** #
# * Subroutine to insert commas into integers. * #
# *********************************************************************** #
sub commas {
local($_) = @_;
1 while s/(.*\d)(\d\d\d)/$1,$2/;
$_;
}
# *********************************************************************** #
# * Print links to any subdirectories. * #
# *********************************************************************** #
sub printDirectories {
$dirfound = 0;
for (sort @filenames) {
if (-d) {
$dirfound = 1;
print " $_
\n";
}
}
if ($dirfound) { print "
\n"; }
}
# *********************************************************************** #
# * Print links to all GIF and JPG files. * #
# *********************************************************************** #
sub printImages {
for (sort @filenames) {
if ((/\.gif$|\.jpg$/) && ($size = -s)) {
print "Filename: $_ ($size bytes)";
if (-l) {
$linkfile = readlink;
print "(symbolic link to '$linkfile')
";
}
print "
";
print "
\n"; } } } # *********************************************************************** # # * Print the top of the HTML page. * # # *********************************************************************** # sub printTop { print "
\n", "\n", "\n", "$bytes bytes in ", "$filecount $file_string ", "($dircount $dir_string)\n", "
\n", "Usage Example: <img src=\"$documentdir/filename.gif\">\n", "\n", "
\n"; } # *********************************************************************** # # * Print the bottom of the HTML page. * # # *********************************************************************** # sub printBottom { print "