Created
December 5, 2008 16:16
-
-
Save voldern/32380 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'sinatra' | |
get '/' do | |
haml :index | |
end | |
post '/' do | |
@error = true | |
@name = params[:file][:filename] | |
file = params[:file][:tempfile] | |
if !file.nil? || !file.empty? | |
if FileUtils.mv(file.path, "/home/voldern/web/dump/public/f/#{@name}") | |
@error = false | |
end | |
end | |
haml :index | |
end | |
get '/f' do | |
@files = Array.new | |
path = 'public/f/' | |
dir = path.split('/')[1] + '/' | |
foo = Dir.glob(path + '*') | |
foo.each do |f| | |
name = f.split('/')[2] | |
size = File.size(path + name) | |
time = File.mtime(path + name) | |
@files << { :name => name, :path => dir + name, :size => size, :time => time } | |
end | |
haml :files | |
end | |
use_in_file_templates! | |
__END__ | |
@@ layout | |
!!! | |
%html | |
%head | |
%title Dump | |
%body | |
= yield | |
@@ index | |
%h1 Dump | |
- if !@error.nil? && !@error | |
%p | |
The file named | |
%a{:href => "f/#{@name}" % @name}= @name | |
was uploaded successfully | |
%form{:method => 'post', :enctype => 'multipart/form-data'} | |
%input{:type => 'file', :name => 'file'}/ | |
%input{:type => 'submit', :value => 'Upload!'}/ | |
@@ files | |
%h1 Files | |
- for file in @files.reverse | |
%p | |
%a{:href => file[:path]}== - #{file[:name]} | |
== [#{file[:size]} bytes] | |
== #{file[:time]} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment