Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: CGI Image on localhost

by Roger (Parson)
on Dec 21, 2003 at 23:09 UTC ( [id://316260]=note: print w/replies, xml ) Need Help??


in reply to CGI Image on localhost

The following is a image slideshow demo I wrote not long ago. Save the script as 'p109.pl' under /cgi-bin.

#!C:/Perl/bin/perl.exe -w use strict; use CGI; my $q = new CGI; my $q_image = $q->param('image'); my $image_url = "/images"; my @images = map { /([^\/]+)$/ } <../htdocs$image_url/*.jpg>; $q_image = $images[0] if ! defined $q_image; my $html = do { local $/; <DATA> }; $html =~ s/%%([^%]*)%%/ if ($1 eq "IMAGE") { image_link() } elsif ($1 eq "PREV") { prev_link() } else { next_link() } /ge; print $q->header, $html; sub image_link { return qq{<img src="$image_url/$q_image" alt="$q_image">}; } sub prev_link { return qq{<a href='/cgi-bin/p109.pl?image=}.get_prev_image().qq{'> +PREV</a>}; } sub next_link { return qq{<a href='/cgi-bin/p109.pl?image=}.get_next_image().qq{'> +NEXT</a>}; } sub get_prev_image { my %hash = map { $images[$_] => $_ } 0..$#images; return $images[$hash{$q_image}-1]; } sub get_next_image { my %hash = map { $images[$_] => $_ } 0..$#images; my $next = $hash{$q_image}+1; $next = 0 if $next > $#images; return $images[$next]; } __DATA__ <HTML> <TITLE>Simple Image Slideshow CGI in Perl</TITLE> <BODY> <TABLE align=center> <tr><td align=center>%%PREV%%</td><td align=center>%%NEXT%%</td></tr> <tr><td colspan=2>%%IMAGE%%</td></tr> </TABLE> </BODY> </HTML>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://316260]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (4)
As of 2025-04-22 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.