it sounds complicated but it's not. The answer is a loop. I'm a perl dev here so bear with me. I'd build a script like so... (bear with me here this is coming off the top of my head on the fly).
First I'd create a database to manage those images. Using unix shell commands you can upload/remove images and just store the names in the database. For example my database would be set up like this:
id (auto_increment)
image_name (full name with extention like image.gif, image2.jpg, image3.png - it'll save you from having to use a custom perl parser and works well with uploading).
basedir (in apache my directories are set up like this - /usr/local/apache/htdocs/images/yourfoldername)
date (datetime) - useful for gallery scripts where you have dated display
Once the database is set up, I would let perl do all the work including counts and printing.
Code:
#!/usr/bin/perl
use strict;
print "Content-type/html\n\n";
my $count = 1;
# Set a default base to start counting for a loop. Perl counts 0 as a number so if you had 1o items
# 0 1 2 3 4 5 6 7 8 9, so I set it to 1 as default (1 2 3 4 5 6 7 8 9 10).
my($dbh,$sth,$rv,$f);
# Connect to the database
our $dbh = DBI->connect("dbi:mysql:$dbname", "root", "password") or &dienice("Can't connect to database: $DBI::errstr"); ## I have a &dienice subroutine
# retrieve the database informaion.
$sth = $dbh->prepare("select *,date_format(date, '%c/%e/%Y') as nicedate from images order by date desc") or &dbdie;
## Desc - descending order. the other option is asc (ascending).
## date_format(date, '%c/%e/%Y') shows date as 1/1/2009. if you want the time in AM or PM change it to
## date_format(date, '%c/%e/%Y %r')
$rv = $sth->execute;
# use a while loop
while ($f = $sth->fetchrow_hashref) {
# define what variables you want to display.
my($image-name) = "$f->{image_name}";
# You'll notice that I used a hyphen (-) instead of an underscore (_). This is to avoid accidental
# syntax errors. Underscores are not a named character and must be backlashed, so a hypen works well.
my($nicedate) = "$f->{nicedate}";
my($basedir) = "$f->{basedir}";
#define a qualified path.
my($fullpath) = "$basedir\/$image-name";
# this is where you print the images how you want them to display. I use print <<NAME so that I don't have to backslash non-named characters. You can also use the CGI mod (use CGI) but it's not entirely necessary).
print <<EndHTML;
<img src="$fullpatth" border="0" width="100" height="100"><br>
Name: $image-name Date: $nicedate
EndHTML
}
loop only work from start to finish while it's true. once you reach the end of the loop you have to initate a start point. so back in your code under the EndHTML you'd put this.
Code:
# Get the count of entries in the database.
my $count_sth = $dbh->prepare("SELECT COUNT(*) FROM images");
$count_sth->execute;
# Your total count would be $count_sth->fetchrow;
# so now you use your default count start and set it to new loop just to print the start.
my @start = ("$count" + ... +" $count_sth->feathrow");
# If you had 10 images for example it would show like this. (1...10)
# to print the first number in the loop you use perl you'd use loop option.
my $first = shift(@start); # will return 1 as the first number
my $last = pop(@start); # will return 10 as the last number
# that counts all of the entries in your image database using 1 as the start.
# when the loop reaches the end you print the first number as a link or automatically redirect to the first.
$sth = $dbh->prepare("select *,date_format(date, '%c/%e/%Y') as nicedate from images order by date desc start $first") or &dbdie;
# that restarts the loop with the first number. all you have to new is print it or auto redirect back to the start.
}
The other, faster option is to do the select count first and make the whole select process a subroutine and after the loop refer back to the subroutine. It's an infinite count if you do that though, so be careful. non-terminating script will blister your server.
If you need to see a whole working version I can build it for you and let you see. I know I talked alot of code and wrote what seems like alot, but that would have taken me 5 minutes at best.
[/code]