From ab0fecd06e4443178b6c39f6715bd9b4fd93d614 Mon Sep 17 00:00:00 2001
From: Paul van Tilburg
Date: Wed, 16 Jun 2010 21:32:22 +0200
Subject: [PATCH] Added upload support (in upload/ for now).
---
plemp.rb | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
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",