Important alert: (current site time 7/15/2013 8:39:04 PM EDT)
 

VB icon

Image Lister (Updated)

Email
Submitted on: 2/14/2001 3:57:25 PM
By: whiteknight  
Level: Intermediate
User Rating: By 9 Users
Compatibility: 5.0 (all versions)
Views: 16792
(About the author)
 
     This script reads a directory and displays the specified number of pictures per pages then prints next and/or previous page at the bottom. All Pictures and Dirs Must Not Have Spaces in the name. This was tested on UNIX & Windows Platforms.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
=**************************************
= Name: Image Lister (Updated)
= Description:This script reads a directory and displays the specified number of pictures per pages then prints next and/or previous page at the bottom.
All Pictures and Dirs Must Not Have Spaces in the name.
This was tested on UNIX & Windows Platforms.
= By: whiteknight
=
=This code is copyrighted and has= limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=169&lngWId=6=for details.=**************************************

#!/usr/bin/perl
$url = "imglist.cgi";#Name Of the File
$root_dir = Path/to/this/file";#
$image_rooturl = "http://your.domain.com/cgi-bin/imageroot";
$total_shown=5;	#total number of images to show
################################DO NOT EDIT BELOW LINE######################################
$img_num = 0;
$total_images = 0;
$remainder = 0;
$done=0;
$invalid=0;
#########################################
# Get info					#
#########################################
&parse;
$image_root = $FORM{'ir'};
$page = $FORM{'page'};
@subdirs = stat("$root_dir$image_root")	or die "Couldn't stat $root_dir$image_root: $!";
#########################################
#HTML HEADER				#
#########################################
print "Content-type: text/html\n\n";
$title = substr($image_root,1,length($image_root)-1);
#print "<html><head><title> Page $page - $title <\/title><\/head><body>\n";
print qq~
<!-- This Script Made by Camalot Designs (http://camalot.virtualave.net)
	Copyright 2000 - 2001 all right reserved.
		To find out more about ImageThumb v1.0 visit camalot designs -->
~;
#########################################
# Format Page # 			#
#########################################
if($page eq "" || $page eq "1" || $page eq "1"){$count = 1; $page eq "1"}
else {$count = int($page) * $total_shown;}
#########################################
# Image Proccessing		#
#########################################
opendir(DIR, $root_dir.$image_root) or die "cannot open $image_root: $!";
	while (defined($file=readdir(DIR))) {
		#Check Each File and if its an image that is allowed
		#and is in the propper format (no spaces in name) then print the image to the html
		if ($img_num >= $count && $img_num <= $count+($total_shown-1)){
			next if $file =~ /^\.\.?$/; #skip . and ..
			if (lc(substr($file,(length($file)-3),3)) eq "jpg" or
				 lc(substr($file,(length($file)-3),3)) eq "bmp" or
				 lc(substr($file,(length($file)-3),3)) eq "gif"	){
			#This Checks To See if the image name is invalid
			@array= split(//,$file);
			foreach $letter(@array){
				if ($letter eq " "){$invalid=1;}
			}
			#if its the fifth image in the row then start a new row
			$temp = $count+5;
			$temp2 = $count+10;
			$temp3 = $count+15;
			$temp4 = count+21;
			if ($img_num eq $temp){print "<\/tr><tr>\n";}
			elsif ($img_num eq $temp2){print "<\/tr><tr>\n";}
			elsif ($img_num eq $temp3){print "<\/tr><tr>\n";}
			elsif ($img_num eq $temp4){print "<\/tr><tr>\n";}
			
			if(!$invalid){
				
				
				print "<td align=\"center\" valign=\"middle\"><a href=$image_rooturl$image_root\/$file target=_new><img src=$image_rooturl$image_root\/$file height=150 width=150 alt=$file></a><\/td>\n";
			}
			else{print "<td align=\"center\" valign=\"middle\" width=\"150\" height=\"150\"><B>Invalid Name<\/b><\/td>\n";}
			$invalid=0;
			}
		}
		$img_num = $img_num+1;
	}
closedir(DIR);
#########################################
#Count/Total Images #
#########################################
$total_images = $img_num;
$num = $total_images/$total_shown;
#Lets get the number of pages we need
@array = split(//,$num);
foreach $letter (@array){
	if (!$done && $letter ne "."){
	$num2 = $num2.$letter;
	#print "<br>$num2";
	}
	elsif(!$done && $letter eq "."){$done=1;}
	elsif($done && $letter ne "."){$remainder=$letter;}
	
}
########################################
# Previous/Page Number/Next#
########################################
if ($page > ($num2+1)){print "<td align=\"center\" valign=\"middle\" width=\"100\%\"><b>This Page Does Not Exist!<br>\n<a href=\"$url\?page=1\&ir=$image_root\">Goto The First Page<\/a><\/b><\/td>";}
$prev = $page-1;
print "	<\/tr><\/table><center><br clear=\"right\">";
if($prev != 0){print "<a href=\"$url\?page=$prev\&ir=$image_root\">Previous<\/a> | ";}
for ($yx=0;$yx < $num2;$yx++){
$pge = $yx+1;
if ($pge ne $page){
print "<a href=\"$url\?page=$pge\&ir=$image_root\">$pge<\/a> | ";}
else{ print "$pge | ";}
}
$nex = $page+1;
if ($nex <=$num2){print "<a href=\"$url\?page=$nex\&ir=$image_root\">Next<\/a>";}
print "<\/center>";
#########################################
#PARSE					#
#########################################
sub parse
	{
		read(STDIN, $input, $ENV{'CONTENT_LENGTH'});
		$input = $ENV{'QUERY_STRING'} if $ENV{'QUERY_STRING'};
		@pairs = split(/&/, $input);
		
		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;
			
		}
}


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.