ruby 文件上传

来源:互联网 发布:图片mv制作软件下载 编辑:程序博客网 时间:2024/06/08 14:19

#encoding: utf-8

class UpDownLoad < ActiveRecord::Base

def self.upload(params,id)

msg = "{success:false}"

if params[:xlsfile].original_filename.split('.')[1] != 'pdf'

return msg

else

file_path = "#{Rails.root}/public/upload_pdf/#{id}.pdf"

File.open("#{file_path}", "wb") do |f|

f.write(params[:xlsfile].read)

msg = "{success:true}"

end

return msg

end

end

end

下载

send_file(session[:file_path], :type => "text/excel;charset=utf-8; header=present", :disposition => 'attachment')

原创粉丝点击