http://www.openspc2.org/reibun/Ruby/cgi_form/005/
でやると、エラーが出る。
apacheのログには
undefined method `[]' for #<StringIO:0xb7f577bc>

で、以下のようにして動くようになった。(v1.8.6)

#!/usr/local/bin/ruby
require "cgi"
$cgi = CGI.new()

def upload
        html="<html><head><title>test</title>"
        html+="<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Shift_JIS\"> "
        html+="</head><body>"

        system("touch /var/tmp/temp")
        system("chmod 666 /var/tmp/temp")
        open("/var/tmp/temp","w") do |fh|
        fh.binmode
        fh.write $cgi['file'].read
        end

        system("mv /var/tmp/temp /var/tmp/file.txt")

        html+="upload completed.<br>\n"
        list=open("|ls -l /var/tmp/file.txt")
        html+= list.gets
        html+="</body></html>"

       $cgi.out do
       html
       end
end

upload

$cgi['file'][0].read
   ↓
$cgi['file'].read
とする。

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2007年05月17日 14:51