Category: | CGI Programming |
Author/Contact Info | /msg cjf |
Description: | Simple little script that reads through a directory, grabs all files with png/jpg/gif extensions and prints them to the browser. |
#!/usr/bin/perl -wT use strict; use CGI; use Image::Size; my $q = new CGI; my $imageDir = "./"; my @images; opendir DIR, "$imageDir" or die "Can't open $imageDir $!"; @images = grep { /\.(?:png|gif|jpg)$/i } readdir DIR; closedir DIR; print $q->header("text/html"), $q->start_html("Images in $imageDir"), $q->p("Here are all the images in $imageDir"); foreach my $image (@images) { my ($width, $height) = imgsize("$image"); print $q->p( $q->a({-href=>$image}, $q->img({-src=>$image, -width=>$width, -height=>$height}) ) ); } print $q->end_html; Update: Applied gav^'s and dws's suggestions listed below. Update: Included jarich's code to use CGI.pm to print out the lines in the foreach loop. |
Back to
Code Catacombs