Upload files to the specified directory

hello

Can you tell me how do i create a page that allows me to have a facility
by which the user can upload a file to the defined folder

pls provide the code for controller,model and view

thanks

dhaval

dhaval wrote:

hello

Can you tell me how do i create a page that allows me to have a facility
by which the user can upload a file to the defined folder

pls provide the code for controller,model and view

thanks

dhaval

Controller action:

def upload
File.open
“#{RAILS_ROOT}/uploads/#{params[:file].original_filename}”, ‘wb’ do |f|
f.write(params[:file].read)
end
redirect_to :action => ‘index’
end

View:

<% form_tag({:action => ‘upload’}, {:multipart => true}) do %>
Upload a file:
<%= file_field_tag ‘file’ %>
<%= submit_tag ‘Submit’ %>
<% end %>

thanx a lot man :slight_smile:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs