Perl・CGI入門/ファイルアップローダ/HTML出力
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
|
ログイン
]
開始行:
''[[FrontPage]]''
* 自作ファイルアップローダのHTML出力部 [#t3b83150]
実際に作成したソースコードを公開します。~
掲示板と同様、機能の観点でファイルを2つに分けています。~
それぞれ、表(HTML出力部: dfh.cgi)と裏(ログファイル作成部:...
ここではログの読込みとHTML出力に特化したdfh.cgiを、コメン...
~
ポイントは、formタグでenctype="multipart/form-data"を記述...
これにより、フォームデータの形式が大きく変わります。~
~
ファイル名: dfh_r2.cgi
#!/usr/bin/perl
use warnings; ...
use strict; ...
...
require './jcode.pl'; ...
...
# Read Cookie ******************************************...
my $cv = ""; ...
my $cname = ""; ...
my $curl = ""; ...
my $cmssid = ""; ...
my $nouse = ""; ...
...
$cv = $ENV{'HTTP_COOKIE'}; ...
...
($cname, $curl, $cmssid, $nouse) = split( /#@#/, $cv ); ...
...
unless( defined $cmssid || $cmssid ne "" ) ...
{ ...
$cmssid = 1; ...
} ...
#/Read Cookie ******************************************...
# Read Log *********************************************...
my @reada = (""); ...
...
open( LOGR, "<./filelog.txt" ) ...
or print "Location: http://bj006.com/cgi/error2.htm"...
flock( LOGR, 1 ) ...
or print "Location: http://bj006.com/cgi/error2.htm"...
@reada = <LOGR>; ...
close LOGR; ...
#/Read Log *********************************************...
# HTML Front *******************************************...
print 'Content-type: text/html'."\n\n"; ...
...
print <<HF; ...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitiona...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; char...
<title>uploader</title>
</head>
<body bgcolor="#B8A470" link="#0099FF" vlink="#999999" a...
<p align="left">
<font size="+7" face="Times New Roman, Times, serif">
<strong>bj006.com File Uploader</strong>
</font>
<font size="3"><br></font>
</p>
<form action="./write.cgi" method="POST" enctype="multip...
<div align="left">
<table width="21%" border=" " bordercolor="#B8A470">
<tr>
<td width="20%">Name:</td> ...
<td colspan="2">
<input name="name" type="text" size="25" max...
</td>
</tr>
<tr>
<td>Comment:</td> ...
<td colspan="2"><input name="comment" type="text...
</tr>
<tr>
<td>File:</td> ...
<td colspan="2"><input name="file" type="file" s...
</tr>
<tr>
<td height="2">Password: </td> ...
<td width="9%" height="2">
<input name="pwd" type="password" size="8" m...
</td>
</tr>
<tr>
<td height="2">URL:</td> ...
<td height="2" colspan="2">
<input name="url" type="text" value="$curl" ...
</td>
</tr>
<tr>
<td height="2">ID: </td> ...
<td width="9%" height="2">
<input name="mssid" type="text" size="4" max...
</td>
<td width="71%" height="2">(input 1-1024) </td>
</tr>
<tr>
<td height="7"></td>
<td height="7" colspan="2">
<input type="submit" name="Upload" value="up...
</td>
</tr>
</table>
</div>
</form> ...
<p align="left"> ...
<a href="http://bj006.com">
<font size="2">
<span style="background-color: #000000">-HOME-</span>
</a>
<a href="http://bj006.com/cgi/aboutuploader">
<span style="background-color: #000000">
このアップローダについての説明
</span>
</font>
</a>
</p>
<table width="75%" border="" bordercolor="#B8A470"> ...
HF
#/HTML Front *******************************************...
# Query ************************************************...
my $qkey = ""; ...
my $page = 0; ...
...
unless( defined $ENV{'QUERY_STRING'} ) ...
{ ...
$page = 0; ...
} ...
else ...
{ ...
($qkey, $page) = split( /=/, $ENV{'QUERY_STRING'} );...
} ...
#/Query ************************************************...
# HTML Log *********************************************...
my $cnt = @reada; ...
my $n = 0; ...
my $no = ($cnt - 10 * $page); ...
...
my $name = ""; ...
my $subject = ""; ...
my $filename = ""; ...
my $url = ""; ...
my $mssid = 0; ...
my $time = ""; ...
my $size = 0; ...
my $ipaddr = ""; ...
my $host = ""; ...
...
while( $no > 0 && $n < 10 ) ...
{ ...
($name, $subject, $filename, $size, $url, $mssid, $t...
$ipaddr, $host, $nouse) = split( /#@#/, $reada...
$n++; ...
...
print <<HL; ...
<tr>
<td>
<table width="720" height="20" border="0" al...
bordercolor="#B8A470" bgcolor="#000000" ...
</td>
</tr>
<tr>
<td height="0" bgcolor="#000000">
<strong>
<font color="#CC0000">
No.$no $name ($mssid) "$subject" $...
</font>
</strong>
</td>
</tr>
<tr>
<td>
<a href = "http://bj006.com/cgi/dfh/attach/$...
<font color="#E0E0E0"> : size = $size byte</...
</td>
</tr>
</table> ...
HL
$no--; ...
} ...
# Log Process ******************************************...
print <<LOG; ...
<tr>
<td>
<a href="http://bj006.com/cgi/dfh/dfh.cgi">
<font size="3">
<strong>
<span style="background-color: #000000">[NEW...
</a> Log →
LOG
...
$page = 1; ...
while( ($cnt - $page * 10) > 0 ) ...
{ ...
print '<a href="http://bj006.com/cgi/dfh/dfh.cgi?pag...
"$page". ...
'"><span style="background-color: #000000"...
"$page". ...
']</span></a> '; ...
$page++; ...
} ...
print '</strong></font></td></tr>'."\n"; ...
#/Log Process ******************************************...
print <<END; ...
<tr>
<td>
<font size="-1">
<strong>Copyright © 2005-2008 baje, All...
</font>
</td>
</tr>
</body> ...
</html> ...
END
#/HTML Log *********************************************...
exit;
** 関連ページ [#r16bbb9c]
[[Perl・CGI入門/パッケージを使う/ID Roll]]~
[[Perl・CGI入門/ファイルアップローダ/ログファイル作成]]
** 修正履歴 [#tedff12b]
-dfh_r2.cgi~
--クッキー読込み部微修正~
#attach( [nolist] ,[noform])
*** 参考ページ [#raf7b681]
http://www.perl-labo.org/~
http://perl.misty.ne.jp/~
[[Perlメモ/CGIモジュール:http://digit.que.ne.jp/work/inde...
終了行:
''[[FrontPage]]''
* 自作ファイルアップローダのHTML出力部 [#t3b83150]
実際に作成したソースコードを公開します。~
掲示板と同様、機能の観点でファイルを2つに分けています。~
それぞれ、表(HTML出力部: dfh.cgi)と裏(ログファイル作成部:...
ここではログの読込みとHTML出力に特化したdfh.cgiを、コメン...
~
ポイントは、formタグでenctype="multipart/form-data"を記述...
これにより、フォームデータの形式が大きく変わります。~
~
ファイル名: dfh_r2.cgi
#!/usr/bin/perl
use warnings; ...
use strict; ...
...
require './jcode.pl'; ...
...
# Read Cookie ******************************************...
my $cv = ""; ...
my $cname = ""; ...
my $curl = ""; ...
my $cmssid = ""; ...
my $nouse = ""; ...
...
$cv = $ENV{'HTTP_COOKIE'}; ...
...
($cname, $curl, $cmssid, $nouse) = split( /#@#/, $cv ); ...
...
unless( defined $cmssid || $cmssid ne "" ) ...
{ ...
$cmssid = 1; ...
} ...
#/Read Cookie ******************************************...
# Read Log *********************************************...
my @reada = (""); ...
...
open( LOGR, "<./filelog.txt" ) ...
or print "Location: http://bj006.com/cgi/error2.htm"...
flock( LOGR, 1 ) ...
or print "Location: http://bj006.com/cgi/error2.htm"...
@reada = <LOGR>; ...
close LOGR; ...
#/Read Log *********************************************...
# HTML Front *******************************************...
print 'Content-type: text/html'."\n\n"; ...
...
print <<HF; ...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitiona...
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; char...
<title>uploader</title>
</head>
<body bgcolor="#B8A470" link="#0099FF" vlink="#999999" a...
<p align="left">
<font size="+7" face="Times New Roman, Times, serif">
<strong>bj006.com File Uploader</strong>
</font>
<font size="3"><br></font>
</p>
<form action="./write.cgi" method="POST" enctype="multip...
<div align="left">
<table width="21%" border=" " bordercolor="#B8A470">
<tr>
<td width="20%">Name:</td> ...
<td colspan="2">
<input name="name" type="text" size="25" max...
</td>
</tr>
<tr>
<td>Comment:</td> ...
<td colspan="2"><input name="comment" type="text...
</tr>
<tr>
<td>File:</td> ...
<td colspan="2"><input name="file" type="file" s...
</tr>
<tr>
<td height="2">Password: </td> ...
<td width="9%" height="2">
<input name="pwd" type="password" size="8" m...
</td>
</tr>
<tr>
<td height="2">URL:</td> ...
<td height="2" colspan="2">
<input name="url" type="text" value="$curl" ...
</td>
</tr>
<tr>
<td height="2">ID: </td> ...
<td width="9%" height="2">
<input name="mssid" type="text" size="4" max...
</td>
<td width="71%" height="2">(input 1-1024) </td>
</tr>
<tr>
<td height="7"></td>
<td height="7" colspan="2">
<input type="submit" name="Upload" value="up...
</td>
</tr>
</table>
</div>
</form> ...
<p align="left"> ...
<a href="http://bj006.com">
<font size="2">
<span style="background-color: #000000">-HOME-</span>
</a>
<a href="http://bj006.com/cgi/aboutuploader">
<span style="background-color: #000000">
このアップローダについての説明
</span>
</font>
</a>
</p>
<table width="75%" border="" bordercolor="#B8A470"> ...
HF
#/HTML Front *******************************************...
# Query ************************************************...
my $qkey = ""; ...
my $page = 0; ...
...
unless( defined $ENV{'QUERY_STRING'} ) ...
{ ...
$page = 0; ...
} ...
else ...
{ ...
($qkey, $page) = split( /=/, $ENV{'QUERY_STRING'} );...
} ...
#/Query ************************************************...
# HTML Log *********************************************...
my $cnt = @reada; ...
my $n = 0; ...
my $no = ($cnt - 10 * $page); ...
...
my $name = ""; ...
my $subject = ""; ...
my $filename = ""; ...
my $url = ""; ...
my $mssid = 0; ...
my $time = ""; ...
my $size = 0; ...
my $ipaddr = ""; ...
my $host = ""; ...
...
while( $no > 0 && $n < 10 ) ...
{ ...
($name, $subject, $filename, $size, $url, $mssid, $t...
$ipaddr, $host, $nouse) = split( /#@#/, $reada...
$n++; ...
...
print <<HL; ...
<tr>
<td>
<table width="720" height="20" border="0" al...
bordercolor="#B8A470" bgcolor="#000000" ...
</td>
</tr>
<tr>
<td height="0" bgcolor="#000000">
<strong>
<font color="#CC0000">
No.$no $name ($mssid) "$subject" $...
</font>
</strong>
</td>
</tr>
<tr>
<td>
<a href = "http://bj006.com/cgi/dfh/attach/$...
<font color="#E0E0E0"> : size = $size byte</...
</td>
</tr>
</table> ...
HL
$no--; ...
} ...
# Log Process ******************************************...
print <<LOG; ...
<tr>
<td>
<a href="http://bj006.com/cgi/dfh/dfh.cgi">
<font size="3">
<strong>
<span style="background-color: #000000">[NEW...
</a> Log →
LOG
...
$page = 1; ...
while( ($cnt - $page * 10) > 0 ) ...
{ ...
print '<a href="http://bj006.com/cgi/dfh/dfh.cgi?pag...
"$page". ...
'"><span style="background-color: #000000"...
"$page". ...
']</span></a> '; ...
$page++; ...
} ...
print '</strong></font></td></tr>'."\n"; ...
#/Log Process ******************************************...
print <<END; ...
<tr>
<td>
<font size="-1">
<strong>Copyright © 2005-2008 baje, All...
</font>
</td>
</tr>
</body> ...
</html> ...
END
#/HTML Log *********************************************...
exit;
** 関連ページ [#r16bbb9c]
[[Perl・CGI入門/パッケージを使う/ID Roll]]~
[[Perl・CGI入門/ファイルアップローダ/ログファイル作成]]
** 修正履歴 [#tedff12b]
-dfh_r2.cgi~
--クッキー読込み部微修正~
#attach( [nolist] ,[noform])
*** 参考ページ [#raf7b681]
http://www.perl-labo.org/~
http://perl.misty.ne.jp/~
[[Perlメモ/CGIモジュール:http://digit.que.ne.jp/work/inde...
ページ名: