#!/usr/local/bin/ruby
require "cgi"

cgi = CGI.new
print cgi.header("type" => "text/html", "charset" => "UTF-8")

# ファイル名取得

if cgi['file'].original_filename =~ /\\([^\\]*)$/
  filename = $1
else
  # それ以外はたぶんこれでいいはず
  filename = File.basename(cgi['file'].original_filename)
end

open("#{filename}","w") do |fh|
  fh.binmode
  fh.write cgi['file'].read
end
