/ Published in: Rails
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
post '/upload' do unless params[:file] && (tmpfile = params[:file][:tempfile]) && (name = params[:file][:filename]) @error = "No file selected" return haml(:upload) end directory = "public/files" path = File.join(directory, name) File.open(path, "wb") { |f| f.write(tmpfile.read) } end ---------------- %form{:action=>"/upload",:method=>"post",:enctype=>"multipart/form-data"} %input{:type=>"file",:name=>"file"} %input{:type=>"submit",:value=>"Upload"}