From f9aaaf38f9c795e3992a0471c6c1822f3ed83394 Mon Sep 17 00:00:00 2001 From: sw <939547590@qq.com> Date: Mon, 27 Apr 2015 14:54:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E7=88=86=E4=B8=8B=E8=BD=BD=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=AD=97=E7=AC=A6=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/zipdown_controller.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index df354f107..0b7357ff2 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -180,14 +180,17 @@ class ZipdownController < ApplicationController 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" zipfile_name = "#{output_path}/#{rename_zipfile}" Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name)) Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile| files_paths.each do |filename| - rename_file = File.basename(filename) - rename_file = filename_to_real( File.basename(filename)) if is_attachment + rename_file = ic.iconv( (File.basename(filename)) ).to_s + rename_file = ic.iconv( filename_to_real( File.basename(filename))).to_s if is_attachment + begin zipfile.add(rename_file, filename) rescue Exception => e