设置zip支持unicode

This commit is contained in:
guange 2015-04-27 14:36:11 +08:00
parent 24ce5191c3
commit 56f6fa0d86
1 changed files with 2 additions and 2 deletions

View File

@ -180,9 +180,9 @@ class ZipdownController < ApplicationController
def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[]) def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[])
ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE')
rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip" rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip"
zipfile_name = "#{output_path}/#{rename_zipfile}" zipfile_name = "#{output_path}/#{rename_zipfile}"
Zip.unicode_names = true
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name)) Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
@ -190,7 +190,7 @@ class ZipdownController < ApplicationController
rename_file = File.basename(filename) rename_file = File.basename(filename)
rename_file = filename_to_real( File.basename(filename)) if is_attachment rename_file = filename_to_real( File.basename(filename)) if is_attachment
begin begin
zipfile.add(ic.iconv(rename_file), filename) zipfile.add(rename_file, filename)
rescue Exception => e rescue Exception => e
zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write l(:label_file_exist)} zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write l(:label_file_exist)}
next next