scripting: dynamically creating, upon request, a webpage including all images in a directory

NikPreviousAcct

No Lifer
Aug 15, 2000
52,763
1
0
Someone told me to look up perl, and I've found a script to do so (and it's listed below), but I'm clueless as to how to use it or what to do with it. :p

If someone has an easy way of setting up a script that will, when activated (link to page clicked), it takes a list of all the images in the directory (remote directory, possibly?) and builds the webpage to include them. So, in theory, I could simply upload a new image, refresh the page, and voila there it would be shown.



Here's the script...

#!/usr/local/bin/perl
#######################################################################
#
# Image Index 1.0
# Show all .gif and .jpg images in a given directory
#
# Goto sections marked 1. and 2. and 3. to make program changes.
# Then place this script in your CGI-BIN folder.
#
# Copyright 1999, Mike Hundt, All Rights Reserved
# email - mchundt@nglic.com
#
#######################################################################
# VARIABLES USED IN CODE
$pos=0;
$upname="";
$count=0;
# 1. BELOW IS THE URL TO THE GRAPHIC IMAGES
$imgpath="http://intranet/graphics/bullets/";
#######################################################################

# 2. CHANGE THE DIRECTORY BELOW TO REPRESENT WHERE THE IMAGES TO SHOW ARE.
# THIS IS SET UP FOR A PATH ON AN NT SERVER, YOU MUST CHANGE FOR UNIX SYSTEMS.
# A UNIX PATH WOULD BE SOMETHING LIKE... /home/user/public_html/graphics/
opendir(CURDIR,"http://www.ffmcobalt.com/smilies/")||die("Cannot open Directory!");

@names=readdir(CURDIR);
print "Content-type: text/html", "\n\n";
print "<html><head><title>Bullets</title></head>\n";
print "<BODY><TABLE BORDER='0' CELLPADDING=4 CELLSPACING =0 WIDTH='100%'>\n";
print "<p align=center><font face=Verdana, Arial, san serif SIZE=+1>Bullets</font></p>\n
<blockquote><blockquote>
<p><font face='Verdana, Arial, san serif' SIZE=-1>You will find these graphics at http://www.ffmcobalt.com.</font></p>
</blockquote></blockquote>";
for $name(@names)
{
if ($count==0)
{
print "<TR>\n";
}
$upname=uc($name);
$pos=index($upname,".GIF");
if ($pos > 0)
{
print "<TD ALIGN='CENTER'><IMG SRC='".$imgpath.$name."'>
<font face='Verdana, Arial, san serif' SIZE=-1>$name</font></TD>\n";
$count=$count+1;
}
# IF YOU HAVE FILES ENDING LIKE .JPEG CHANGE BELOW TO .JP
$pos=index($upname,".JPG");
if ($pos > 0)
{
print "<TD ALIGN='CENTER'><IMG SRC='".$imgpath.$name."'>
<font face='Verdana, Arial, san serif' SIZE=-1>$name</font></TD>\n";
$count=$count+1;
}

# 3. CHANGE THE NUMBER BELOW TO HOW MANY COLUMNS TO DISPLAY ACCROSS THE PAGE.
if ($count==4)
{
print "</TR>\n";
$count=0;
}
}
closedir(CURDIR);
if ($count>0)
{
print "</TR>\n";
}
print "</TABLE></body></html>\n";
 

KevinMU1

Senior member
Sep 23, 2001
673
0
0
You'll need to have cgi-bin access in order to run such scripts. Do you have a cgi-bin directory and perl access with your web host?

Assuming that you do, you can just stick that into your cgi-bin directory and should just be able to hit it like ".../cgi-bin/script.pl" You will need to also make sure it has the right permissions, you can chmod 777 it in order to ensure it is executable to all users (although 777 is a bad idea, although I can't remember the numbering scheme at the moment, that'll work though).

Hope that helps.