⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch13.htm

📁 美国Macmillan出版社编写的Perl教程《Perl CGI Web Pages for WINNT》
💻 HTM
📖 第 1 页 / 共 5 页
字号:
			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>

&lt;HTML&gt;

&lt;TITLE&gt;Goo Goo Artist's Search&lt;/TITLE&gt;

&lt;BODY bgcolor=&quot;#40E0D0&quot; Text=&quot;#191970&quot; &gt;

&lt;CENTER&gt;

&lt;H1&gt;The Goo Goo Site Search&lt;/H1&gt;

&lt;/CENTER&gt;

&lt;HR&gt;

&lt;P&gt;

&lt;B&gt;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.

&lt;P&gt;

&lt;FORM METHOD=POST ACTION=&quot;http://www.googoo.com/cgi-bin/findstuf.pl&quot;&gt;

&lt;INPUT TYPE=RADIO NAME=&quot;band&quot; VALUE=&quot;TPF&quot;&gt;The Petite Fauves

&lt;BR&gt;

&lt;INPUT TYPE=RADIO NAME=&quot;band&quot; VALUE=&quot;PU&quot;&gt;Push Up

&lt;BR&gt;

&lt;INPUT TYPE=RADIO NAME=&quot;band&quot; VALUE=&quot;TDL&quot;&gt;Ten Days Late 

&lt;BR&gt;

&lt;INPUT TYPE=RADIO NAME=&quot;band&quot; VALUE=&quot;ST&quot;&gt;Seoul Train

&lt;BR&gt;

&lt;INPUT TYPE=RADIO NAME=&quot;band&quot; VALUE=&quot;AL&quot;&gt;Angry Lemon

&lt;BR&gt;

&lt;HR&gt;

&lt;INPUT TYPE=SUBMIT VALUE=&quot;Select&quot;&gt;

&lt;/FORM&gt;

&lt;P&gt;

&lt;/BODY&gt;

&lt;/HTML&gt;

</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 &quot;galleries&quot; 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(/&amp;/, $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(&quot;C&quot;,hex($1))/eg;

		$FORM{$name}=$value;

	}

	print &quot;Content-type: text/html\n\n&quot;;

	print &lt;&lt;&quot;EOF&quot;;

&lt;HTML&gt;

&lt;TITLE&gt;Gallery for $FORM{band}&lt;/TITLE&gt;

&lt;BODY&gt;

&lt;H1&gt; Seasrch Results for $FORM{band}&lt;/H1&gt;

&lt;HR&gt;&lt;P&gt;

&lt;H3&gt;Video Clips&lt;/H3&gt;

&lt;UL&gt;

EOF

	foreach $file (&lt;&quot;c:\\googoo\\bands\\$FORM{band}\\video\\*.mpg&quot;&gt;) {

		print &quot;&lt;LI&gt;&lt;A

HREF=\&quot;bands/$FORM{band}/video/$file\&quot;&gt;$file&lt;/a&gt;&lt;BR&gt;&quot;;

	}

	print &quot;&lt;/UL&gt;\n&quot;;

	print &quot;&lt;P&gt;&lt;H3&gt;Sound Bites&lt;/H3&gt;\n&lt;UL&gt;\n&quot;;

	foreach $file (&lt;&quot;c:\\googoo\\bands\\$FORM{band}\\audio\\*.wav&quot;&gt;) {

		print &quot;&lt;LI&gt;&lt;A

HREF=\&quot;bands/$FORM{band}/audio/$file\&quot;&gt;$file&lt;/a&gt;&lt;BR&gt;&quot;;

	}

	print &quot;&lt;/UL&gt;\n&quot;;

	print &quot;&lt;P&gt;&lt;H3&gt;Pictures&lt;/H3&gt;\n&lt;UL&gt;\n&quot;;

	foreach $file (&lt;&quot;c:\\googoo\\bands\\$FORM{band}\\images\\*.jpg&quot;&gt;) {

		print &quot;&lt;LI&gt;&lt;A

HREF=\&quot;bands/$FORM{band}/images/$file\&quot;&gt;$file&lt;/a&gt;&lt;BR&gt;&quot;;

	}

	print &quot;&lt;/UL&gt;\n&quot;;

	print &quot;&lt;/BODY&gt;\n&lt;/HTML&gt;\n&quot;;

}



else {		# if there were problems with the form, print an error.

	print &quot;Content-type: text/html\n\n&quot;;

        print &quot;&lt;HTML&gt;\n&quot;;

       	print &quot;&lt;title&gt;Error - Form Error&lt;/title&gt;\n&quot;;

       	print &quot;&lt;h1&gt;Error: Form Error&lt;/h1&gt;\n&quot;;

       	print &quot;&lt;P&gt;&lt;hr&gt;&lt;P&gt;\n&quot;;

       	print &quot;There was an error with the Form. Please\n&quot;;

       	print &quot;contact GooGoo Records at &lt;address&gt;&lt;a

href=\&quot;mailto:support@www.googoo.com\&quot;&gt;support@googoo.com&lt;/a&gt;&lt;/address&gt;\n&quot;;

       	print &quot;&lt;/HTML&gt;\n&quot;;                                             		exit;

}

</PRE>

</BLOCKQUOTE>

<P>

The program basically scans the directory of the band selected

and looks for file extensions for any image files (&quot;.jpg&quot;),

sound files (&quot;.wav&quot;), and video files (&quot;.mpg&quot;).

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>

&lt;HTML&gt;

&lt;HEAD&gt;

&lt;TITLE&gt;Goo Goo Downloads&lt;/TITLE&gt;

&lt;/HEAD&gt;

&lt;BODY bgcolor=&quot;#40E0D0&quot; Text=&quot;#191970&quot;&gt;

&lt;H1&gt;Goo Goo Instant Download Page!&lt;/H1&gt;&lt;BR&gt;

&lt;HR&gt;

&lt;B&gt;

Select the band for whom you want to see the selection of pictures, videos,

and sound clips.

&lt;P&gt;

&lt;FORM METHOD=POST ACTION=&quot;http://www.googoo.com/cgi-bin/findzips.pl&quot;&gt;

&lt;INPUT TYPE=RADIO NAME=&quot;band&quot; VALUE=&quot;TPF&quot;&gt;The Petite Fauves

&lt;BR&gt;

&lt;INPUT TYPE=RADIO NAME=&quot;band&quot; VALUE=&quot;PU&quot;&gt;Push Up

&lt;BR&gt;

&lt;INPUT TYPE=RADIO NAME=&quot;band&quot; VALUE=&quot;TDL&quot;&gt;Ten Days Late 

&lt;BR&gt;

&lt;INPUT TYPE=RADIO NAME=&quot;band&quot; VALUE=&quot;ST&quot;&gt;Seoul Train

&lt;BR&gt;

&lt;INPUT TYPE=RADIO NAME=&quot;band&quot; VALUE=&quot;AL&quot;&gt;Angry Lemon

&lt;BR&gt;

&lt;/FORM&gt;

&lt;P&gt;

&lt;/BODY&gt;

&lt;/HTML&gt;

</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(/&amp;/, $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(&quot;C&quot;,hex($1))/eg;

		$FORM{$name}=$value;

	}

	print &quot;Content-type: text/html\n\n&quot;;

	print &lt;&lt;&quot;EOF&quot;;

&lt;HTML&gt;

&lt;TITLE&gt; Selections for $FORM{band}&lt;/TITLE&gt;

&lt;BODY&gt;

&lt;H1&gt; Selections for $FORM{band}&lt;/H1&gt;

&lt;HR&gt;&lt;P&gt;

&lt;H3&gt;Video&lt;/H3&gt;

&lt;UL&gt;

EOF

	foreach $file (&lt;&quot;c:\\googoo\\bands\\$FORM{band}\\video\\*.zip&quot;&gt;) {

		print &quot;&lt;LI&gt;&lt;A

HREF=\&quot;bands/$FORM{band}/video/$file\&quot;&gt;$file&lt;/a&gt;&lt;BR&gt;&quot;;

	}

	print &quot;&lt;/UL&gt;\n&quot;;

	print &quot;&lt;P&gt;&lt;H3&gt;Audio&lt;/H3&gt;\n&lt;UL&gt;\n&quot;;

	foreach $file (&lt;&quot;c:\\googoo\\bands\\$FORM{band}\\audio\\*.zip&quot;&gt;) {

		print &quot;&lt;LI&gt;&lt;A

HREF=\&quot;bands/$FORM{band}/audio/$file\&quot;&gt;$file&lt;/a&gt;&lt;BR&gt;&quot;;

	}

	print &quot;&lt;/UL&gt;\n&quot;;

	print &quot;&lt;P&gt;&lt;H3&gt;Pictures&lt;/H3&gt;\n&lt;UL&gt;\n&quot;;

	foreach $file (&lt;&quot;c:\\googoo\\bands\\$FORM{band}\\pics\\*.zip&quot;&gt;) {

		print &quot;&lt;LI&gt;&lt;A

HREF=\&quot;bands/$FORM{band}/pics/$file\&quot;&gt;$file&lt;/a&gt;&lt;BR&gt;&quot;;

	}

	print &quot;&lt;/UL&gt;\n&quot;;

	print &quot;&lt;/BODY&gt;\n&lt;/HTML&gt;\n&quot;;

     }

     else { # if there were problems with the form, print an error.

          print &quot;Content-type: text/html\n\n&quot;;

          print &quot;&lt;HTML&gt;\n&quot;;

          print &quot;&lt;title&gt;Error - Form Error&lt;/title&gt;\n&quot;;

          print &quot;&lt;h1&gt;Error: Form Error&lt;/h1&gt;\n&quot;;

          print &quot;&lt;P&gt;&lt;hr&gt;&lt;P&gt;\n&quot;;

          print &quot;There was an error with the Form. Please\n&quot;;

          print &quot;contact GooGoo Records at &lt;address&gt;&lt;a

href=\&quot;mailto:support@www.googoo.com\&quot;&gt;support@googoo.com&lt;/a&gt;&lt;/address&gt;\n&quot;;

          print &quot;&lt;/HTML&gt;\n&quot;

          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 + -