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.
#!/usr/bin/perl -wT # photo_display.pl # script to select a category and display images within that directory # sends data to photo_display2.pl use CGI qw( :standard ); $startdir="/www/htdocs/photos"; # all images are in subdirectories o +f this directory push(@dirs,$startdir); foreach $dir (@dirs) { opendir(DIR,"$dir") || die ( "Error opening : $!" ); @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( header() ); print( start_html( -title => "Image Gallery", -dtd => '-//W3C//DTD HTML 4.01 Transitional//EN', -meta=>{'description'=>'Image Gallery', -created=>'20020926'}, -style =>{'src'=>'http:/photos/css/photos.css'}, -background =>'http:/images/flatwhit.gif' ) ); print '<h1>Image Gallery</h1>'; print '<hr />'; parse(); print <<FORM; <form action=/cgi-bin/photos/photo_display2.pl method=post> <select name=pic> <option value=$FORM{'pic'} selected>$FORM{'pic'} FORM @sortdirs = sort @dirs; foreach $thisdir (@sortdirs) { my $short = $thisdir; $short =~ s/\/www\/htdocs\/photos\///; # display only subdirectory +as option in dropdown print "<option value=$thisdir>$short</option>"; } print '<input type="submit" value="View Images"></form>'; print ( end_html() ); 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; } }


#!/usr/bin/perl -wT # photo_display2.pl # display images within a directory # receives directory information from photo_display.pl use CGI qw( :standard ); print( header() ); print( start_html( -title => "USGS Photos", -dtd => '-//W3C//DTD HTML 4.01 Transitional//EN', -meta=>{'description'=>'Photo Gallery', -created=>'20020926'}, -style =>{'src'=>'http:/photos/css/photos.css'}, -background =>'http:/images/flatwhit.gif' ) ); print '<h1>Image Gallery</h1>'; print '<hr />'; print '<p>Click on an image to view a larger version.</p>'; my $dir = param( "pic" ); opendir(DIR,$dir) || die ("Error opening : $!" ); #directory contains text files that should not be used @piclist = grep { !/^\.\.?$/ and /\.jpg$|\.gif$|\.png$|\.JPG$|\.bmp$/ +} readdir(DIR); @sortpiclist = sort @piclist; #images will display in alphanumeric or +deR closedir(DIR); print "<table cellpadding=10 cellspacing=0 width=100%>"; while (@sortpiclist) { my @row_entries= splice (@sortpiclist, 0, 4); print "<tr>"; for (@row_entries) { print "<td>"; $dir =~ s/\/www\/htdocs//; print qq| <a href=$dir/$_> <img src=$dir/$_ border="0" width="180"></a><br>$_<p> |; print "</td>"; } print "</tr>"; } print ( end_html() );

In reply to Re: simple image gallery generated by server image directory by kryberg
in thread simple column/row counter by monkscafe

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.