📄 ch13.htm
字号:
print "Your old favorite color is: $gbcolor\n";
print "Your new favorite color is: $color\n";
}
print "</H3>\n</BODY>\n</HTML>\n";
exit;
}
}
close (MEMBER);
open (MEMBER, ">>member.pl");
print MEMBER "$newline";
print "Thank you, $id! Your name has been added to the Membership Database.\n";
print "</H3>\n</BODY>\n</HTML>\n";
close(MEMBER);
</PRE>
</BLOCKQUOTE>
<H3><A NAME="Searching">
Searching</A></H3>
<P>
The most powerful aspect to the Goo Goo Records Web site is the
ability for the user to search through the Goo Goo Records databases
and find all the information available concerning a particular
artist or band that records on the Goo Goo Records label. This
information could be images, sounds, or even video clips. The
HTML for this page looks like this:
<BLOCKQUOTE>
<PRE>
<HTML>
<TITLE>Goo Goo Artist's Search</TITLE>
<BODY bgcolor="#40E0D0" Text="#191970" >
<CENTER>
<H1>The Goo Goo Site Search</H1>
</CENTER>
<HR>
<P>
<B>Search the Goo Goo site instantly for your favourite band. Just select the band you
want to see, and a complete list of pictures, videos, and sound clips for that band will appear.
<P>
<FORM METHOD=POST ACTION="http://www.googoo.com/cgi-bin/findstuf.pl">
<INPUT TYPE=RADIO NAME="band" VALUE="TPF">The Petite Fauves
<BR>
<INPUT TYPE=RADIO NAME="band" VALUE="PU">Push Up
<BR>
<INPUT TYPE=RADIO NAME="band" VALUE="TDL">Ten Days Late
<BR>
<INPUT TYPE=RADIO NAME="band" VALUE="ST">Seoul Train
<BR>
<INPUT TYPE=RADIO NAME="band" VALUE="AL">Angry Lemon
<BR>
<HR>
<INPUT TYPE=SUBMIT VALUE="Select">
</FORM>
<P>
</BODY>
</HTML>
</PRE>
</BLOCKQUOTE>
<P>
When the name of the band in question is entered by the user,
this script searches the databases and presents a Web page of
the results, generated on the fly by the script. The result is
a list of different "galleries" that are created from
the existing files in each band's directory. An example of a successful
search is found in Figure 13.7.
<P>
<A HREF="f13-7.gif" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/f13-7.gif"><B>Figure 13.7 :</B> <I>Results of an artist search</I>.</A>
<P>
By creating new galleries each time, they are always current,
and to maintain them all the Web Master has to do is keep up-to-date
files in each band's directory.
<P>
The script to do this is written as follows:
<BLOCKQUOTE>
<PRE>
#!/usr/bin/perl
#findstuf.pl
# This is the script to find audio, video, and picture files of a band
# It will search for *.wav, *.mpg, and *.jpg in the appropriate directory under
# the selected band name and print them in a generated page.
#
#####################################################################
if ($ENV{'REQUEST_METHOD'} EQ 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/, $buffer);
# This is the Name-Value pair splitter.. Put into $FORM array
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;
}
print "Content-type: text/html\n\n";
print <<"EOF";
<HTML>
<TITLE>Gallery for $FORM{band}</TITLE>
<BODY>
<H1> Seasrch Results for $FORM{band}</H1>
<HR><P>
<H3>Video Clips</H3>
<UL>
EOF
foreach $file (<"c:\\googoo\\bands\\$FORM{band}\\video\\*.mpg">) {
print "<LI><A
HREF=\"bands/$FORM{band}/video/$file\">$file</a><BR>";
}
print "</UL>\n";
print "<P><H3>Sound Bites</H3>\n<UL>\n";
foreach $file (<"c:\\googoo\\bands\\$FORM{band}\\audio\\*.wav">) {
print "<LI><A
HREF=\"bands/$FORM{band}/audio/$file\">$file</a><BR>";
}
print "</UL>\n";
print "<P><H3>Pictures</H3>\n<UL>\n";
foreach $file (<"c:\\googoo\\bands\\$FORM{band}\\images\\*.jpg">) {
print "<LI><A
HREF=\"bands/$FORM{band}/images/$file\">$file</a><BR>";
}
print "</UL>\n";
print "</BODY>\n</HTML>\n";
}
else { # if there were problems with the form, print an error.
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<title>Error - Form Error</title>\n";
print "<h1>Error: Form Error</h1>\n";
print "<P><hr><P>\n";
print "There was an error with the Form. Please\n";
print "contact GooGoo Records at <address><a
href=\"mailto:support@www.googoo.com\">support@googoo.com</a></address>\n";
print "</HTML>\n"; exit;
}
</PRE>
</BLOCKQUOTE>
<P>
The program basically scans the directory of the band selected
and looks for file extensions for any image files (".jpg"),
sound files (".wav"), and video files (".mpg").
The files listed on the HTML document returned are based on what
the script finds in each band's directory. This script can be
easily modified to accommodate other formats of these files.
<P>
From these results a user can select a particular result and be
taken straight to the file. Each of these galleries (Image, Sound,
and Video) can now be used by the member.
<H4>The Image Gallery</H4>
<P>
When a member user enters the image gallery, they are requested
to select the band of their choice. This request is used to make
an on-the-fly gallery page(s) that is created from all images
from a single directory of that band. As each directory is updated,
the Gallery pages for that directory are updated as well.
<P>
The search and Web page creation is done by this script, which
first finds the directory necessary, then makes the Web page using
all the .jpg files found in that directory.
<H4>The Sound Gallery</H4>
<P>
Along the same lines as the Image Gallery, the Sound Gallery is
also created by a script that first checks for the selected band's
directory, then scans for any .wav files that might be in there.
The result for the member user is a freshly generated HTML document
that would resemble in format the image gallery, because basically
it is the image gallery, only with sound files this time.
<H4>The Video Gallery</H4>
<P>
As you might have already guessed, the Video Gallery is similar
to the last two galleries. It uses a script which finds the specified
directory, then returns an HTML document based on the .mpg files
it finds.
<H3><A NAME="Downloads">
Downloads</A></H3>
<P>
To make the site operate more efficiently, the Goo Goo Records
Web Master has included compressed files in all the different
bands' directories to make the image, sound, and video files download
faster.
<P>
To create a list of zipped files available for download, this
HTML document is used:
<BLOCKQUOTE>
<PRE>
<HTML>
<HEAD>
<TITLE>Goo Goo Downloads</TITLE>
</HEAD>
<BODY bgcolor="#40E0D0" Text="#191970">
<H1>Goo Goo Instant Download Page!</H1><BR>
<HR>
<B>
Select the band for whom you want to see the selection of pictures, videos,
and sound clips.
<P>
<FORM METHOD=POST ACTION="http://www.googoo.com/cgi-bin/findzips.pl">
<INPUT TYPE=RADIO NAME="band" VALUE="TPF">The Petite Fauves
<BR>
<INPUT TYPE=RADIO NAME="band" VALUE="PU">Push Up
<BR>
<INPUT TYPE=RADIO NAME="band" VALUE="TDL">Ten Days Late
<BR>
<INPUT TYPE=RADIO NAME="band" VALUE="ST">Seoul Train
<BR>
<INPUT TYPE=RADIO NAME="band" VALUE="AL">Angry Lemon
<BR>
</FORM>
<P>
</BODY>
</HTML>
</PRE>
</BLOCKQUOTE>
<P>
which creates a page that looks just like Figure 13.8.
<P>
<A HREF="f13-8.gif" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/f13-8.gif"><B>Figure 13.8 :</B> <I>The download generation page</I>.</A>
<P>
The script to facilitate this download list, which is generated
based on a search through a selected band's directory, goes like
this:
<BLOCKQUOTE>
<PRE>
#!/usr/bin/perl
# findzips.pl
###################################################
#
# This is the script to find audio, video, and picture files of a band to
# download.
# It will search for *.zip in the appropriate directory under
# the selected band name and print them in a generated page with links to the
# zip files to be downloaded.
#
#########################################################
if ($ENV{'REQUEST_METHOD'} EQ 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs=split(/&/, $buffer);
# This is the Name-Value pair splitter.. Put into $FORM array
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;
}
print "Content-type: text/html\n\n";
print <<"EOF";
<HTML>
<TITLE> Selections for $FORM{band}</TITLE>
<BODY>
<H1> Selections for $FORM{band}</H1>
<HR><P>
<H3>Video</H3>
<UL>
EOF
foreach $file (<"c:\\googoo\\bands\\$FORM{band}\\video\\*.zip">) {
print "<LI><A
HREF=\"bands/$FORM{band}/video/$file\">$file</a><BR>";
}
print "</UL>\n";
print "<P><H3>Audio</H3>\n<UL>\n";
foreach $file (<"c:\\googoo\\bands\\$FORM{band}\\audio\\*.zip">) {
print "<LI><A
HREF=\"bands/$FORM{band}/audio/$file\">$file</a><BR>";
}
print "</UL>\n";
print "<P><H3>Pictures</H3>\n<UL>\n";
foreach $file (<"c:\\googoo\\bands\\$FORM{band}\\pics\\*.zip">) {
print "<LI><A
HREF=\"bands/$FORM{band}/pics/$file\">$file</a><BR>";
}
print "</UL>\n";
print "</BODY>\n</HTML>\n";
}
else { # if there were problems with the form, print an error.
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<title>Error - Form Error</title>\n";
print "<h1>Error: Form Error</h1>\n";
print "<P><hr><P>\n";
print "There was an error with the Form. Please\n";
print "contact GooGoo Records at <address><a
href=\"mailto:support@www.googoo.com\">support@googoo.com</a></address>\n";
print "</HTML>\n"
exit;
}
</PRE>
</BLOCKQUOTE>
<P>
From this script the result is sent to the user, and the result
resembles Figure 13.9.
<P>
<A HREF="f13-9.gif" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/f13-9.gif"><B>Figure 13.9 :</B> <I>A download request page result</I>.</A>
<H2><A NAME="TheSalesForm"><FONT SIZE=5 COLOR=#FF0000>
The Sales Form</FONT></A></H2>
<P>
With all of this information about Goo Goo Records' musical artists
available free of charge to the site's members, registered users
will be given the opportunity to purchase Goo Goo Records merchandise,
CD's, and t-shirts. To do this they would fill out and send in
the online form created with HTML,which produces an HTML document
that looks like Figure 13.10.
<P>
<A HREF="f13-10.gif" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/f13-10.gif"><B>Figure 13.10:</B> <I>The Goo Goo Records sales form</I>.</A>
<P>
The programming for this sales page is as follows:
<BLOCKQUOTE>
<PRE>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -