post by yamamoto | 0 | 594 views

ファイルアップロードの CGI を gawk で作ってみよう!

<html>

<head>

<title>ファイルアップロード</title>

</head>

<body>

【gawk プログラム】

<!–  fromの属性に enctype="multipart/form-data" を付けるのを忘れずに! //–>

<form method="post" action="/cgi-bin/gawk.cgi" enctype="multipart/form-data">

<input type=text name="path">

<input type="file" name="file1" size="60" />

<input type="file" name="file2" size="60" />

<input type="submit" name="submit" value="送信" />

</form>

</body>

</html>

#! /usr/bin/gawk -f

BEGIN{

 print "Content-Type: text/plain"

 print ""

 print "This is test"

 print 1,ENVIRON[“AUTH_TYPE”]

 print 2,ENVIRON[“CONTENT_LENGTH”]

 print 3,ENVIRON[“CONTENT_TYPE”]

 print 4,ENVIRON[“GATEWAY_INTERFACE”]

 print 5,ENVIRON[“PATH_INFO”]

 print 6,ENVIRON[“PATH_TRANSLATED”]

 print 7,ENVIRON[“QUERY_STRING”]

 print 8,ENVIRON[“REMOTE_ADDR”]

 print 9,ENVIRON[“REMOTE_HOST”]

 print 10,ENVIRON[“REMOTE_IDENT”]

 print 11,ENVIRON[“REMOTE_USER”]

 print 12,ENVIRON[“REQUEST_METHOD”]

 print 13,ENVIRON[“SCRIPT_NAME”]

 print 14,ENVIRON[“SERVER_NAME”]

 print 15,ENVIRON[“SERVER_PORT”]

 print 16,ENVIRON[“SERVER_PROTOCOL”]

 print 17,ENVIRON[“SERVER_SOFTWARE”]

 system("rm /var/www/win/up/myfile")

}

{

 print $0 >> "/var/www/win/up/myfile"

}

——WebKitFormBoundaryMU4Bxx8HoqSOyTQG

Content-Disposition: form-data; name="path"

myPath

——WebKitFormBoundaryMU4Bxx8HoqSOyTQG

Content-Disposition: form-data; name="file1"; filename="README"

Content-Type: application/octet-stream

<テキストデータ;省略>

——WebKitFormBoundaryMU4Bxx8HoqSOyTQG

Content-Disposition: form-data; name="file2"; filename="google日本語.png"

Content-Type: image/png

?PNG

<PNG画像データ;省略>

——WebKitFormBoundaryMU4Bxx8HoqSOyTQG

Content-Disposition: form-data; name="submit"

送信

——WebKitFormBoundaryMU4Bxx8HoqSOyTQG–

Comments are closed.