index.html/dinput.cgi

index.html/dinput.cgi

INDEX.HTML
<html>
<head>
<title>フォトデータベース</title>
</head>
<body bgcolor=”#FFFFFF” text=”#000000″>
<h2>フォトデータベース input</h2>
<hr size=”1″>
<form method=”POST” name=”formIn” action=”dinput.cgi” enctype=”multipart/form-data”>
画像の名前:<input type=”text” name=”name” value=””><br>
カテゴリー:<input type=”text” name=”category” value=””><br>
<p><input type=”file” name=”upload_file” size=”32″></p>
<input type=”submit” name=”submit” value=”送信”>
<input type=”reset” name=”submit” value=”リセット”>
</form></body><
DINPUT.CGI

#!/usr/bin/perl
BEGIN{$|=1;print”Content-type:text/html\n\n”;open(STDERR,
“>&STDOUT”);}
use CGI;
$query=new CGI;
#ファイル名の取得
$filename=$query->param(‘upload_file’);
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);
#######################################################

$name=$query->param(‘name’);
$category=$query->param(‘category’);
##################################

#外部ファイルに書き込む##################
@data=”$day\t$name\t$category\t$gazou\n”;

open(FILE,”>>save.txt”)||&error(“$datafile 外部ファイルが開きませんでしたエラー”);
print FILE @data;
close(FILE);

######################################

print<<END;

<html><head><title>フォトデータベースinput</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=Shift_JIS”>
</head>

<body bgcolor=”#FFFFFF” text=”#000000″>
<div align=”center”><h1><b>フォトデータベース入力</b></h1>
</div>

<hr>
データが保存されました。<br>

END
print”<img src=\”images/$gazou\” width=\”200px\” height=\”auto\”>\n”;

print”</body></html>\n”;

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です