Added upload support (in upload/ for now).

This commit is contained in:
Paul van Tilburg 2010-06-16 21:32:22 +02:00
parent cf93b1d8fc
commit ab0fecd06e
1 changed files with 20 additions and 0 deletions

View File

@ -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",