Quick Search for:  in language:    
UNIX,script,reads,directory,displays,specifie
   Code/Articles » |  Newest/Best » |  Community » |  Jobs » |  Other » |  Goto » | 
CategoriesSearch Newest CodeCoding ContestCode of the DayAsk A ProJobsUpload
Perl Stats

 Code: 74,273. lines
 Jobs: 25. postings

 How to support the site

 
Sponsored by:

 
You are in:
 
Login





Latest Code Ticker for Perl.
Click here to see a screenshot of this code!Mailing List v2.0
By Aaron L. Anderson on 1/7

(Screen Shot)

ShowIMG
By Jeff Mills on 1/5


Simple Perl Ping
By John Hass on 12/29


Very basic login script template with cookies
By Aaron L. Anderson on 12/29


Click here to put this ticker on your site!


Add this ticker to your desktop!


Daily Code Email
To join the 'Code of the Day' Mailing List click here!

Affiliate Sites



 
 
   

Image Lister (Updated)

Print
Email
 
VB icon
Submitted on: 2/14/2001 3:57:25 PM
By: whiteknight  
Level: Intermediate
User Rating: By 9 Users
Compatibility:5.0 (all versions)

Users have accessed this code 5697 times.
 

 
     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 direct
    =     ory 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://w
    =     ww.Planet-Source-Code.com/vb/scripts/Sho
    =     wCode.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 notify us if this entry should be deleted (i.e contains no code, is a virus, etc.).
Reason:
 
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!
Note:Not only will your feedback be posted, but an email will be sent to the code's author in your name.

NOTICE: The author of this code has been kind enough to share it with you.  If you have a criticism, please state it politely or it will be deleted.

For feedback not related to this particular code, please click here.
 
Name:
Comment:

 

Categories | Articles and Tutorials | Advanced Search | Recommended Reading | Upload | Newest Code | Code of the Month | Code of the Day | All Time Hall of Fame | Coding Contest | Search for a job | Post a Job | Ask a Pro Discussion Forum | Live Chat | Feedback | Customize | Perl Home | Site Home | Other Sites | About the Site | Feedback | Link to the Site | Awards | Advertising | Privacy

Copyright© 1997 by Exhedra Solutions, Inc. All Rights Reserved.  By using this site you agree to its Terms and Conditions.  Planet Source Code (tm) and the phrase "Dream It. Code It" (tm) are trademarks of Exhedra Solutions, Inc.