|
|
@ -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
|