LoginSignup
0
0

More than 3 years have passed since last update.

Ruby: ファイルのアップロード (cgi)

Last updated at Posted at 2021-04-12

upload_ruby.png

upload_ruby.html
<!DOCTYPE html>
<html lang="ja">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>upload ruby (Apr/12/2021)</title>
</head>
<body>
<h2>HTML5</h2>
<form method="post" action="upload_ruby.rb" enctype="multipart/form-data">
<input type="file" name="files"  multiple>
<p><input type="submit" value="送信する"></p>
</form>

<blockquote>
<p>File is uploaded to ./data_work.</p>
<p>複数のファイルのアップロードができない。</p>
</blockquote>
<hr />
Apr/12/2021 AM 08:25<p />
</body>
</html>
upload_ruby.rb
#! /usr/bin/ruby
# -*- coding: utf-8 -*-
#
#   upload_ruby.rb
#
#                   Apr/12/2021
#
# --------------------------------------------------------------------
require "cgi"
# --------------------------------------------------------------------
form = CGI.new
print "Content-type: text/html\n\n"
print "Now Uploading...<br />"
print form.keys
print "<br />"
print form.params
print "<br />"
print "*** aaaa ***<br />"
print form['files']
print "<br />"
print form['files'].length
print "<br />"
print form['files'].class.to_s + "<br>"
print form['files'].original_filename + "<br>"
#
#
output_dir = "./data_work"
open(output_dir + "/" + form['files'].original_filename, "w") {|fh|
    fh.write form['files'].read
}
#
print "Upload End"
# --------------------------------------------------------------------
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0