in reply to •Re: simple column/row counter
in thread simple column/row counter

Thanks Monks!!! @row_entries= splice (@piclist, 0, 5); was a new concept for me. It doesn't appear in Learning Perl and is only given a cursory glance in Programming Perl. The final code for this is below. Just set the root of your images directory. Simple and quick. I tried to keep the code readable (and because I'm still a Perl novice). This displays 5 images per row, then it starts again (thanks Randal!) Just before the image src HTML, I'm stripping off the full path and assuming the image path is /images/$_
$startdir="/www/intranet/images"; push(@dirs,$startdir); foreach $dir (@dirs) { opendir(DIR,"$dir") || die "opendir $dir failed"; @list = grep(!/^\.\.?$/,readdir(DIR)); closedir(DIR); foreach $item (@list) { $fullname = $dir."/".$item; # add the directory name to th +e file name if (-d $fullname) { push(@dirs,$fullname); print "$item<br>"; } } } print "Content-type:text/html\n\n"; &parse; print qq| <html> <head> <link rel="stylesheet" type="text/css" href="/include/style.css"/> </head> <body> <p> <form action=/cgi-bin/images.cgi method=post> <select name=pic> <option value=$FORM{'pic'} selected>$FORM{'pic'} |; foreach $thisdir (@dirs) { print qq| <option value="$thisdir">$thisdir |; } print qq| <input type=submit value="Go!"> </form> </html> |; opendir(DIR,"$FORM{'pic'}") || die "opendir $dir failed"; @piclist = grep(!/^\.\.?$/,readdir(DIR)); closedir(DIR); print "<table cellpadding=10 cellspacing=0 width=100%>"; while (@piclist) { my @row_entries= splice (@piclist, 0, 5); print "<tr>"; for (@row_entries) { print "<td>"; $FORM{'pic'} =~ s/\/www\/intranet//; print qq| <img src=$FORM{'pic'}/$_><br>$_<p> |; print "</td>"; } print "</tr>"; } sub parse { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } }

Replies are listed 'Best First'.
Re: simple image gallery generated by server image directory
by kryberg (Pilgrim) on Sep 26, 2002 at 13:38 UTC
    This is totally cool! I have been working on a vary similar thing for a web-based photo gallery. I had users picking a category (directory) from a form, then generated a page of images and text description by
Re: simple image gallery generated by server image directory
by kryberg (Pilgrim) on Sep 30, 2002 at 16:46 UTC
    I thought this code was really neat because I was working on something similar. So I took it and made some changes, that hopefully improve it.

    I also broke it up into two files because of some of the other things I'm going to add for my specific project.

    I would be interested to know if anybody else has suggestions on how to make it better, just to help me learn.

    Also, even though it works for me, I really don't understand what the line $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; is doing. If anybody can help shed some light on that, I'd appreciate it.