diff --git a/plemp.rb b/plemp.rb index 413f298..62ce18b 100644 --- a/plemp.rb +++ b/plemp.rb @@ -1,4 +1,5 @@ require "camping" +require "fileutils" require "markaby" require "pathname" @@ -6,6 +7,7 @@ Camping.goes :Plemp Markaby::Builder.set(:indent, 2) PUBLIC_DIR = Pathname.new(__FILE__).dirname + "public" +UPLOAD_DIR = Pathname.new(__FILE__).dirname + "upload" module Plemp::Controllers @@ -38,6 +40,17 @@ module Plemp::Controllers end end + class Upload + def post + orig_ext = File.extname(@input.file[:filename]) + new_file = UPLOAD_DIR + Time.now.strftime("%Y%m%d%H%M%S#{orig_ext}") + new_file.open("w") do |f| + f.write(@input.file[:tempfile].read) + end + redirect Index + end + end + end module Plemp::Views @@ -57,6 +70,13 @@ module Plemp::Views end def main + form :action => R(Upload), :method => "post", + :enctype => "multipart/form-data" do + p do + input :name => "file", :id => "file", :type => "file" + input :type => "submit", :value => "Upload!" + end + end div.first! :style => "position:absolute;top:120px;left:100px", :onmousedown => "drag(event)" do "First" end div.second! :style => "position:absolute;top:170px;left:300px",