def upload_file
if !params['upload_file'].nil?
file = params['upload_file']
file_upload(file)
end
end
def file_upload(upload)
begin
FileUtils.mkpath(upload_path) unless File.directory?(upload_path)
if upload.kind_of?(StringIO)
upload.rewind
end
orig_name = upload.original_filename
base_name = File.basename(orig_name, ".*") # 取得文件名字
ext_name = File.extname(orig_name) # 取得文件扩展名
# 重命名
file_name = base_name + '_' + Time.now.strftime("%y%m%d") + ext_name
# 将文件写入磁盘
File.open(upload_path(file_name), "wb") { |f| f.write(upload.read) }
rescue
raise
end
redirect_to '/service/upload_file'
end
# 生成绝对路径
def upload_path(file_name = nil)
"#{RAILS_ROOT}/public/tagfiles/#{file_name.nil? ? '' : file_name}"
end
if !params['upload_file'].nil?
file = params['upload_file']
file_upload(file)
end
end
def file_upload(upload)
begin
FileUtils.mkpath(upload_path) unless File.directory?(upload_path)
if upload.kind_of?(StringIO)
upload.rewind
end
orig_name = upload.original_filename
base_name = File.basename(orig_name, ".*") # 取得文件名字
ext_name = File.extname(orig_name) # 取得文件扩展名
# 重命名
file_name = base_name + '_' + Time.now.strftime("%y%m%d") + ext_name
# 将文件写入磁盘
File.open(upload_path(file_name), "wb") { |f| f.write(upload.read) }
rescue
raise
end
redirect_to '/service/upload_file'
end
# 生成绝对路径
def upload_path(file_name = nil)
"#{RAILS_ROOT}/public/tagfiles/#{file_name.nil? ? '' : file_name}"
end