zip
root path firefox bug
This commit is contained in:
yanxd 2014-04-15 21:13:56 +08:00
parent c34f2da385
commit 28bebb1ee7
3 changed files with 16 additions and 2 deletions

View File

@ -1,5 +1,8 @@
source 'https://rubygems.org' source 'https://rubygems.org'
gem 'rubyzip'
gem 'zip-zip'
gem 'iconv'
gem "rails", "3.2.13" gem "rails", "3.2.13"
gem "jquery-rails", "~> 2.0.2" gem "jquery-rails", "~> 2.0.2"
gem "i18n", "~> 0.6.0" gem "i18n", "~> 0.6.0"

View File

@ -15,6 +15,8 @@ class TestController < ApplicationController
zipfile = ziping homeworks_attach_path zipfile = ziping homeworks_attach_path
send_file zipfile, :filename => bid.name, send_file zipfile, :filename => bid.name,
:type => detect_content_type(zipfile) :type => detect_content_type(zipfile)
rescue Errno::ENOENT => e
logger.error "[Errno::ENOENT] ===> #{e}"
end end
@ -23,14 +25,15 @@ class TestController < ApplicationController
end end
def ziping files_path def ziping files_path
ic = Iconv.new('GBK//IGNORE', 'UTF-8//IGNORE')
folder = "#{Rails.root}/files" folder = "#{Rails.root}/files"
input_filename = files_path input_filename = files_path
zipfile_name = "#{Rails.root}/tmp/archiveZip/archive_#{Time.now.to_i}.zip" zipfile_name = "#{Rails.root}/tmp/archiveZip/archive_#{Time.now.to_i}.zip"
Rails.logger.info "================================================================================================================================================================================================================================================================================================================================================================================================#{zipfile_name}"
Dir.mkdir(File.dirname(zipfile_name)) if File.exist?(File.dirname(zipfile_name)) Dir.mkdir(File.dirname(zipfile_name)) if 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|
input_filename.each do |filename| input_filename.each do |filename|
zipfile.add(File.basename(filename), folder + '/' + filename) zipfile.add(ic.iconv(filename_to_real(File.basename(filename))), folder + '/' + filename)
end end
zipfile.get_output_stream("ReadMe"){ |os| zipfile.get_output_stream("ReadMe"){ |os|
os.write "Homeworks" os.write "Homeworks"
@ -43,4 +46,11 @@ class TestController < ApplicationController
content_type = Redmine::MimeType.of(name) content_type = Redmine::MimeType.of(name)
content_type.to_s content_type.to_s
end end
def filename_to_real name
attach = Attachment.find_by_disk_filename(name)
attach.filename
end
end end

View File

@ -456,6 +456,7 @@ ul.projects li.root
width:auto; width:auto;
float:center; float:center;
min-height:800px; min-height:800px;
border: 1px solid #ffffff;
} }
/*by huang*/ /*by huang*/