1.CGI.pm
1.1 查看已经安装的perl模块 : find `perl -e ' print "@INC" ' ` -name ' *.pm ' -print | grep CGI
确定CGI模块是否安装.
1.2 配置Apache以允许CGI.
ScriptAlias /cgi/ /home/httpd/cgi-bin/ #配置路径
<Directory /home/httpd/cgi-bin> #配置权限
Options +ExecCGI
Order allow,deny
Allow from all
</Directory>
1.3 上传文件
index.html
<html>
<body>
<form method="POST" action="/cgi/test.cgi" ENCTYPE="multipart/form-data">
FILE:
<input type="file" name="FILE">
<br>
<input type="submit" value="Upload!">
</form>
</body>
</html>
test.cgi
#!/usr/bin/perl -w
use CGI;
print "Content-type: text/html/n/n";
my $q = new CGI;
my $file = $q->param("FILE");
print "$file<br>";
my $filename = $file;
$filename =~ s/^.*(open (OUTFILE, ">$basedir/$fileName");
binmode(OUTFILE);
while (my $bytesread = read($file, my $buffer, 1024)) {
print OUTFILE $buffer;
}
close (OUTFILE);
1.4 获取网页访问次数
读取apache的access_log文件获取网页的访问次数.
$num = `grep -c 'GET / HTTP' /apache_path/logs/access_log` ;
1.5 自动刷新网页
<meta http-equiv="refresh" content="300; url=target.html">
并不是perl web编程 但很有用.
The Common Gateway Interface (CGI) is the workhorse of Web-based application development.
CGI.pm
Resources:
CGI.pm
http://stein.cshl.org/WWW/software/CGI/cgi_docs.html
HTML::Template
http://html-template.sourceforge.net/
Apache/mod_perl
http://perl.apache.org/
<<Professional Perl Development>> Randy Kobes