Main »

Picst


#!/usr/bin/perl -wT

# name this code picst.cgi
# dump into a directory with a bunch of pictures.
# when browsed to, will dynamically generate urls for all the pictures in the dir.
# pictures open in a new browser window when url is clicked on.

my $urlVar = "dir=";
$urlVar = $ENV{'QUERY_STRING'} if $ENV{'QUERY_STRING'};
my ($key, $dir) = split /=/,$urlVar;
$dir =~ s/^\/|\/$//g;
my @subDir = split /\//,$dir;
my $urlRoot = $ENV{SCRIPT_NAME};
$urlRoot =~ s/\?.+$/\//;  # remove the get values in the url
my $cgiName = $urlRoot;
$cgiName =~ s/\/$//;
$cgiName =~ s/^.+\///g; # want clean cgi name 
my $navBar = "  <a href=\"$cgiName\">home</a>" if($dir ne ''); # want url for 'home' if not at home.
$navBar = "home" if($dir eq '');  # no url if at home.
$navBar .= genNavBar(@subDir); # get dir branch and set up nav bar.

print "Content-type: text/html\n\n";
print <<EOP;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Expires" CONTENT="Mon, 23 Sep 1996 01:21:00 GMT">
<META http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<TITLE>my pics</TITLE>
<STYLE TYPE="TEXT/CSS">
<!--
A:link
	{
	color:#dddd00;
	font-size:small;
	font-family:arial;
	font-style:normal;
	font-weight:normal;
	text-decoration:none;
	}
A:active
	{
	color:#ffff00;
	font-size:small;
	font-family:arial;
	font-style:normal;
	font-weight:normal;
	}
A:visited
	{
	color:#999900;
	font-size:small;
	font-family:arial;
	font-style:normal;
	font-weight:normal;
	}
A:hover
	{
	color:#ffff00;
	font-size:small;
	font-family:arial;
	font-style:normal;
	font-weight:normal;
	}
-->
</STYLE>
</HEAD>
<BODY bgcolor = "#000000" link=DDDD00 alink=ffff00 vlink=#999900><font color=#ffddff size=2>
EOP

  #print "<br>debug:: urlRoot=$urlRoot; cgiName=$cgiName; urlVar=$urlVar; key=$key; dir=$dir <br>\n";
print "<br>&nbsp; $navBar <br><br>\n";

opendir(DIR,"./$dir")
   || die "NO SUCH Directory: Images";

foreach $file ( sort readdir(DIR) ){
  if($file =~ /^(\.||\.\.||index.html|RCS|.*\.cgi|.*\.swp)$/i){next;}
	my $fullDir = "$dir/$file/";
	$fullDir =~ s/^\/|\/$//g; # remove leading or trailing slashes
	   #print "fullDir=$fullDir :: <br>\n";
	if(-d $fullDir){print " &nbsp;&nbsp; <a href=\"$cgiName\?dir=$fullDir\">dir-&gt; $file</a><br>\n";}
        else{print " &nbsp;&nbsp; <a href=\"$fullDir\" target=\"_blank\">$file</a><br>\n";}
   }
closedir(DIR);

print "<br></body></html>\n";

sub genNavBar { # generate the nav bar to get back
	my @dirs = @_;  # sent cginame, dir array
	my ($cnt,$updir,$navString);
	my $arrayCnt = scalar @dirs;
	foreach my $dir (@dirs){
		$cnt++;
		$updir .= "$dir/";
		if($cnt < $arrayCnt){$navString .= qq' / <a href="?dir=$updir">$dir</a>';}
		else{$navString .= " / $dir"};
	}
return($navString);
} # end of sub genNavBar.


top level subjects:

Page last modified on September 25, 2009, at 08:41 PM

^