I need a script that views all images in a directory, and because the directory contains a lot of images, I want the newest image to be presented first.
(I'm not very familiar with cgi, I read but don't write the code...)
I've found a simple script that views the images, but they are sorted alfabetically.
Is there a simple way to modify the script to present the newest image first, or do you know a better way to do this?
Here's the script:
=====================================
#!/usr/bin/perl
# CHANGE LINE ABOVE IF NECESSARY TO LOCATION OF YOUR PERL INTERPRETER.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# WebImageLister 1.0
# --------------------
# A no-frills VERY simple but VERY effective, easy-to-install Perl
# script to display .GIF, .JPG, .JPEG, .PNG and .BMP images in a table
# as clickable thumbnails from a single web directory.
#
# Defaults: Thumbnails -- 80 pixels wide. Table width -- 7 columns.
#
# IMPORTANT: Lines in ALL CAPS indicate where changes can or *must* be made
# to customize script for your system and/or preferences.
#
# Script must be run from a cgi-bin directory on the web server.
#
# Source of script: #
# Adapted by Henry Baker from a generic script found somewhere on the Web.
# Website: # Email: hbaker@ipa.net
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$pos=0;
$upname="";
$count=0;
# YOU *MUST* CHANGE THIS URL *BETWEEN* THE QUOTE MARKS TO YOUR IMAGE DIRECTORY.
# BE SURE TO INCLUDE THE TRAILING SLASH.
$imgpath="
# UNIX SYSTEM PATH (DEFAULT)
# ----------------------------
# YOU *MUST* CHANGE THE PATH BELOW *BETWEEN* THE QUOTE MARKS (the ALL CAPS STUFF)
# TO POINT TO YOUR IMAGE DIRECTORY.
opendir(curdir,"/home/website/ open Directory!"
# NT SYSTEM PATH (CHANGE FOR AN NT SERVER)
# ------------------------------------------
# FOR AN NT SYSTEM CHANGE THIS PATH *BETWEEN* THE QUOTE MARKS TO POINT TO
# YOUR IMAGE DIRECTORY. REMOVE THE COMMENT POUND SIGN (#) BEFORE IT AND
# PLACE A COMMENT POUND SIGN BEFORE THE UNIX SYSTEM PATH ABOVE.
# opendir(CURDIR,"E:\\ open Directory!"
@names=readdir(curdir);
print "content-type: text/html", "\n\n";
# CHANGE TEXT BETWEEN TITLE TAGS TO REFLECT YOUR HTML PAGE TITLE:
print "<html><head><title>Image Directory Demo</title></head>\n";
print "<body bgcolor=black><center><table bgcolor='#cecece' border='0' cellpadding=2 cellspacing=0 width='100%'>\n";
# CHANGE TEXT IN NEXT LINE TO HEADING FOR YOUR IMAGE DIRECTORY:
print "<center><font face=verdana, arial, san serif size=+2 color=white><b>WebImageLister Images Directory Demo</b></font>\n
<br><font face='Verdana, Arial, san serif' SIZE=-1 color=white><b>(Click images to open in new window)</b></font></center></br>";
# FOR LARGER OR SMALLER THUMBNAILS, CHANGE PIXEL WIDTH NUMBERS IN NEXT FIVE ARRAYS:
for $name(@names)
{
if ($count==0)
{
print "<tr>\n";
}
$upname=uc($name);
$pos=index($upname,".GIF"
if ($pos > 0)
{
print "<td align='center'><a href='".$imgpath.$name."' target=_blank><img src='".$imgpath.$name."' width=80></a><br><font face='verdana, arial, san serif' size=-1>$name</font></td>\n";
$count=$count+1;
}
$pos=index($upname,".JPG"
if ($pos > 0)
{
print "<td align='center'><a href='".$imgpath.$name."' target=_blank><img src='".$imgpath.$name."' width=80></a><br><font face='verdana, arial, san serif' size=-1>$name</font></td>\n";
$count=$count+1;
}
$pos=index($upname,".JPEG"
if ($pos > 0)
{
print "<td align='center'><a href='".$imgpath.$name."' target=_blank><img src='".$imgpath.$name."' width=80></a><br><font face='verdana, arial, san serif' size=-1>$name</font></td>\n";
$count=$count+1;
}
$pos=index($upname,".PNG"
if ($pos > 0)
{
print "<td align='center'><a href='".$imgpath.$name."' target=_blank><img src='".$imgpath.$name."' width=80></a><br><font face='verdana, arial, san serif' size=-1>$name</font></td>\n";
$count=$count+1;
}
$pos=index($upname,".BMP"
if ($pos > 0)
{
print "<td align='center'><a href='".$imgpath.$name."' target=_blank><img src='".$imgpath.$name."' width=80></a><br><font face='verdana, arial, san serif' size=-1>$name</font></td>\n";
$count=$count+1;
}
# CHANGE THE NUMBER IN THE NEXT LINE TO HOW MANY COLUMNS YOU WANT IN IMAGE TABLE:
if ($count==7)
{
print "</tr>\n";
$count=0;
}
}
closedir(curdir);
if ($count>0)
{
print "</tr>\n";
}
print "</table></center></body></html>\n";
==================================
(I'm not very familiar with cgi, I read but don't write the code...)
I've found a simple script that views the images, but they are sorted alfabetically.
Is there a simple way to modify the script to present the newest image first, or do you know a better way to do this?
Here's the script:
=====================================
#!/usr/bin/perl
# CHANGE LINE ABOVE IF NECESSARY TO LOCATION OF YOUR PERL INTERPRETER.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# WebImageLister 1.0
# --------------------
# A no-frills VERY simple but VERY effective, easy-to-install Perl
# script to display .GIF, .JPG, .JPEG, .PNG and .BMP images in a table
# as clickable thumbnails from a single web directory.
#
# Defaults: Thumbnails -- 80 pixels wide. Table width -- 7 columns.
#
# IMPORTANT: Lines in ALL CAPS indicate where changes can or *must* be made
# to customize script for your system and/or preferences.
#
# Script must be run from a cgi-bin directory on the web server.
#
# Source of script: #
# Adapted by Henry Baker from a generic script found somewhere on the Web.
# Website: # Email: hbaker@ipa.net
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
$pos=0;
$upname="";
$count=0;
# YOU *MUST* CHANGE THIS URL *BETWEEN* THE QUOTE MARKS TO YOUR IMAGE DIRECTORY.
# BE SURE TO INCLUDE THE TRAILING SLASH.
$imgpath="
# UNIX SYSTEM PATH (DEFAULT)
# ----------------------------
# YOU *MUST* CHANGE THE PATH BELOW *BETWEEN* THE QUOTE MARKS (the ALL CAPS STUFF)
# TO POINT TO YOUR IMAGE DIRECTORY.
opendir(curdir,"/home/website/ open Directory!"
# NT SYSTEM PATH (CHANGE FOR AN NT SERVER)
# ------------------------------------------
# FOR AN NT SYSTEM CHANGE THIS PATH *BETWEEN* THE QUOTE MARKS TO POINT TO
# YOUR IMAGE DIRECTORY. REMOVE THE COMMENT POUND SIGN (#) BEFORE IT AND
# PLACE A COMMENT POUND SIGN BEFORE THE UNIX SYSTEM PATH ABOVE.
# opendir(CURDIR,"E:\\ open Directory!"
@names=readdir(curdir);
print "content-type: text/html", "\n\n";
# CHANGE TEXT BETWEEN TITLE TAGS TO REFLECT YOUR HTML PAGE TITLE:
print "<html><head><title>Image Directory Demo</title></head>\n";
print "<body bgcolor=black><center><table bgcolor='#cecece' border='0' cellpadding=2 cellspacing=0 width='100%'>\n";
# CHANGE TEXT IN NEXT LINE TO HEADING FOR YOUR IMAGE DIRECTORY:
print "<center><font face=verdana, arial, san serif size=+2 color=white><b>WebImageLister Images Directory Demo</b></font>\n
<br><font face='Verdana, Arial, san serif' SIZE=-1 color=white><b>(Click images to open in new window)</b></font></center></br>";
# FOR LARGER OR SMALLER THUMBNAILS, CHANGE PIXEL WIDTH NUMBERS IN NEXT FIVE ARRAYS:
for $name(@names)
{
if ($count==0)
{
print "<tr>\n";
}
$upname=uc($name);
$pos=index($upname,".GIF"
if ($pos > 0)
{
print "<td align='center'><a href='".$imgpath.$name."' target=_blank><img src='".$imgpath.$name."' width=80></a><br><font face='verdana, arial, san serif' size=-1>$name</font></td>\n";
$count=$count+1;
}
$pos=index($upname,".JPG"
if ($pos > 0)
{
print "<td align='center'><a href='".$imgpath.$name."' target=_blank><img src='".$imgpath.$name."' width=80></a><br><font face='verdana, arial, san serif' size=-1>$name</font></td>\n";
$count=$count+1;
}
$pos=index($upname,".JPEG"
if ($pos > 0)
{
print "<td align='center'><a href='".$imgpath.$name."' target=_blank><img src='".$imgpath.$name."' width=80></a><br><font face='verdana, arial, san serif' size=-1>$name</font></td>\n";
$count=$count+1;
}
$pos=index($upname,".PNG"
if ($pos > 0)
{
print "<td align='center'><a href='".$imgpath.$name."' target=_blank><img src='".$imgpath.$name."' width=80></a><br><font face='verdana, arial, san serif' size=-1>$name</font></td>\n";
$count=$count+1;
}
$pos=index($upname,".BMP"
if ($pos > 0)
{
print "<td align='center'><a href='".$imgpath.$name."' target=_blank><img src='".$imgpath.$name."' width=80></a><br><font face='verdana, arial, san serif' size=-1>$name</font></td>\n";
$count=$count+1;
}
# CHANGE THE NUMBER IN THE NEXT LINE TO HOW MANY COLUMNS YOU WANT IN IMAGE TABLE:
if ($count==7)
{
print "</tr>\n";
$count=0;
}
}
closedir(curdir);
if ($count>0)
{
print "</tr>\n";
}
print "</table></center></body></html>\n";
==================================