The following code was used to upload an image file to the web server. Source code origin:
Ruby Language Stuff | mod_ruby File upload scripts [zytrax.com]
file: file_upload.cgi
require 'cgi'
require 'stringio'
cgi = CGI.new()
puts "Content-Type: text/plain"
puts
print '<result>'
tmpfile = cgi.params['myfile'].first.path
tmpfile = cgi.params['myfile'][0].path
fromfile = cgi.params['myfile'].first
puts fromfile.original_filename
puts fromfile.content_type
tofile = '/var/www/yourdomain.com/htdocs/r/'+fromfile.original_filename
File.open(tofile.untaint, 'w') { |file| file << fromfile.read}
print '</result>'
file: file_upload.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>File upload</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
</head>
<body>
<form name='fileupload' enctype="multipart/form-data"
action='/p/file_upload.cgi' method='post'>
<input type='file' name='myfile' size="40" />
<input type='submit' value"Send it"/>
</form>
</body>
</html>