diff --git a/app/controllers/zipdown_controller.rb b/app/controllers/zipdown_controller.rb index 386e5733d..d9a9e1def 100644 --- a/app/controllers/zipdown_controller.rb +++ b/app/controllers/zipdown_controller.rb @@ -10,14 +10,14 @@ class ZipdownController < ApplicationController #勿删 before_filter :authorize, :only => [:assort,:download_user_homework] SAVE_FOLDER = "#{Rails.root}/files" OUTPUT_FOLDER = "#{Rails.root}/files/archiveZip" + MAX_PATH = 50 #统一下载功能 def download if User.current.logged? begin if params[:base64file] - file = Base64.decode64(params[:base64file]) - file = file.sub('*', '+') + file = decode64(params[:base64file]) send_file "#{OUTPUT_FOLDER}/#{file}", :filename => filename_for_content_disposition(file), :type => detect_content_type(file) else send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => filename_for_content_disposition(params[:filename]), :type => detect_content_type(params[:file]) @@ -125,7 +125,11 @@ class ZipdownController < ApplicationController end def encode64(str) - Base64.encode64(str).sub('+', '*') + Base64.urlsafe_encode64(str) + end + + def decode64(str) + Base64.urlsafe_decode64(str) end def zip_homework_common homework_common @@ -242,6 +246,12 @@ class ZipdownController < ApplicationController def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[]) rename_zipfile = zip_name_refer ||= "#{Time.now.to_i.to_s}.zip" + # 文件名过长 + + if rename_zipfile.size > MAX_PATH + rename_zipfile = rename_zipfile[0,rename_zipfile.size-4][0,MAX_PATH-4] + rename_zipfile[-4,4] + end + zipfile_name = "#{output_path}/#{rename_zipfile}" Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))