20251030
edit.cgi
#!/usr/bin/perl
BEGIN{ $| = 1; print “Content-type: text/html\n\n”; open(STDERR, “>&STDOUT”); }
use CGI;
$query = new CGI;
open(IN, “< save.txt”);
@data=<IN>;
close (IN);
print <<END;
<html>
<head>
<title>フォトデータベース edit</title>
</head>
<body bgcolor=”#FFFFFF” text=”#000000″>
<div align=”center”>
<h1><b>フォトデータベース edit</b></h1>
</div>
<hr>
<form action=”editc.cgi” method=”POST”>
<table border=”1″ width=”100%”>
<tr>
<td>年月日</td><td>名前</td><td>category</td><td>画像</td><td>修正ボタン</td>
</tr>
END
for($i=0;$i<@data;$i++){
@retudata=split(/\t/,$data[$i]);
for($j=0;$j<=$retudata;$j++)
{print”<tr>\n”;
print”<td>@retudata[0]</td><td>@retudata[1]</td><td>@retudata[2]</td>
<td><img.jpg=\”images/@retudata[3]\”width=\”100px\”height=\”auto\”></td>
<td><input type=\”submit\” value=\”$i\” name=\”edit\”></tr>\n”;
}
};
print”</table></form></body></html>”;
editc.cgi
#!/usr/bin/perl
BEGIN{ $| = 1; print “Content-type: text/html\n\n”; open(STDERR, “>&STDOUT”); }
use CGI;
$query = new CGI;
$edit = $query->param(‘edit’);
open(IN, “< save.txt”);
@data=<IN>;
close (IN);
print <<END;
<html>
<head>
<title>フォトデータベース edit</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=Shift_JIS”>
</head>
<body bgcolor=”#FFFFFF” text=”#000000″>
<div align=”center”>
<h1><b>フォトデータベース edit</b></h1>
</div>
<hr>
END
@cdata=@data[$edit];
###################################################
for($i=0;$i<@cdata;$i++){
@moto=split(/\t/,$cdata[$i]);
};
######################################
print”<form method=\”POST\” name=\”formin\” action=\”iedit.cgi\”
enctype=\”multipart/form-data\” >\n”;
print”お名前 <input type=\”text\” name=\”name\” value=\”$moto[1]\”><br>\n”;
print”カテゴリー:<input type=\”text\” name=\”category\” value=\”$moto[2]\”><br>\n”;
print”<input type=\”hidden\” name=\”mphoto\” value=\”$moto[3]\”>\n”;
print”<input type=\”hidden\” name=\”edit\” value=\”$edit\”>\n”;
print”<p><input type=\”file\” name=\”upload_file\” size=\”32\”></p>\n”;
print”<p><input type=\”submit\” name=\”submit\” value=\”send\”><input type=\”reset\”
name=\”submit2\” value=\”reset\”></p>\n”;
print”</form>\n”;
print”<hr>\n”;
print”</body></html>\n”;
iedit.cgi
#!/usr/bin/perl
BEGIN{ $| = 1; print “Content-type: text/html\n\n”; open(STDERR, “>&STDOUT”); }
use CGI;
$query = new CGI;
open(IN, “< save.txt”);
@data=<IN>;
close (IN);
######################
$name = $query->param(‘name’);
$category = $query->param(‘category’);
$gazou = $query->param(‘mphoto’);
$edit = $query->param(‘edit’);
$filename = $query->param(‘upload_file’);
#if 文
###################################################
if($filename eq ”){
#画像なし
#時間を取得##########
local($nsec,$nmin,$nhour,$nmday,$nmon,$nyear)=localtime(time);
$nmon++;
$nyear+=1900;
$day=”$nyear/$nmon/$nmday”;
#######################
$arenge = “$day\t$name\t$category\t$gazou”;
#######################
print <<END;
<html>
<head>
<title>フォトデータベース edit</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=Shift_JIS”>
</head>
<body bgcolor=”#FFFFFF” text=”#000000″>
<div align=”center”>
<h1><b>フォトデータベース edit</b></h1>
</div>
<hr>
END
for($i=0;$i<@data;$i++){
if($i=~m/$edit/){
@data[$i] =$arenge;
}
}
###########################
open(FILE,”>save.txt”)||&error(“save.txt 外部ファイルが開きませんでしたエラー”);
print FILE @data;
close(FILE);
###########################
print”edit complete\n”;
print”</html></body>\n”;
exit;
#else 文
###################################################
#画像あり
}else{
if($filename !~m/\.jpg$/){die”画像ファイルが適応しておりません。jpg ファイルでお願いします。”;}
##########################
# 画像 MIME タイプの取得
$type = $query->uploadInfo($filename)->{‘Content-Type’};
while($bytesread = read($filename, $buffer, 2048)) {
$file .= $buffer;
}
#画像の名前をアクセスタイムから取得#
local($nsec,$nmin,$nhour,$nmday,$nmon,$nyear)=localtime(time);
$nmon++;
$nyear+=1900;
$gazouname=”$nyear$nmon$nmday$nhour$nmin$nsec”;
$day = “$nyear/$nmon/$nmday”;
$gazou = “$gazouname.jpg”;
#外部ファイルに書き込む##
open(OUT, “> images/$gazou”) or die(“ファイルの保存に失敗しました。”);
binmode(OUT);
print(OUT $file);
close(OUT);
#時間を取得################
local($nsec,$nmin,$nhour,$nmday,$nmon,$nyear)=localtime(time);
$nmon++;
$nyear+=1900;
$day=”$nyear/$nmon/$nmday”;
###########################
$arenge = “$day\t$name\t$category\t$gazou\n”;
###########################
print <<END;
<html>
<head>
<title>フォトデータベース edit</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=Shift_JIS”>
</head>
<body bgcolor=”#FFFFFF” text=”#000000″>
<div align=”center”>
<h1><b>フォトデータベース edit</b></h1>
</div>
<hr>
END
for($i=0;$i<@data;$i++){
if($i=~m/$edit/){
@data[$i] = $arenge;
}
}
@dat=@data;
open(FILE,”>save.txt”)||&error(“save.txt 外部ファイルが開きませんでしたエ
ラー”);
print FILE @dat;
close(FILE);
print”edit complete”;
print”</html></body>\n”;
}
exit;

