When I using "file_field" to upload a file:
<%= file_field 'upload', 'datafile' %>
The file name can be obtained in the controller:
params[:upload]['datafile'].original_filename
but how can I obtain the size and type of the file?
When I using "file_field" to upload a file:
<%= file_field 'upload', 'datafile' %>
The file name can be obtained in the controller:
params[:upload]['datafile'].original_filename
but how can I obtain the size and type of the file?
Use the content_type and size helper functions
params[:upload]['datafile'].content_type
Not sure why you'd want to do that in a controller, but any validation needs to be moved inside your model. Also try using a plugin like Paperclip or SWFUpload to handle uploads, for greater flexibility.
Try these links for a examples Paperclip, Attachment_fu, SWFUpload