|
|
@ -1,4 +1,8 @@
|
|
|
|
require 'zip'
|
|
|
|
#coding=utf-8
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
require "base64"
|
|
|
|
|
|
|
|
require 'zip'
|
|
|
|
|
|
|
|
|
|
|
|
class ZipdownController < ApplicationController
|
|
|
|
class ZipdownController < ApplicationController
|
|
|
|
#查找项目(课程)
|
|
|
|
#查找项目(课程)
|
|
|
|
before_filter :find_project_by_bid_id, :only => [:assort]
|
|
|
|
before_filter :find_project_by_bid_id, :only => [:assort]
|
|
|
@ -11,7 +15,12 @@ class ZipdownController < ApplicationController
|
|
|
|
def download
|
|
|
|
def download
|
|
|
|
if User.current.logged?
|
|
|
|
if User.current.logged?
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
send_file "#{OUTPUT_FOLDER}/#{params[:file]}", :filename => filename_for_content_disposition(params[:filename]), :type => detect_content_type(params[:file])
|
|
|
|
if params[:base64file]
|
|
|
|
|
|
|
|
file = Base64.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])
|
|
|
|
|
|
|
|
end
|
|
|
|
rescue => e
|
|
|
|
rescue => e
|
|
|
|
render file: 'public/no_file_found.html'
|
|
|
|
render file: 'public/no_file_found.html'
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -107,7 +116,9 @@ class ZipdownController < ApplicationController
|
|
|
|
bid_homework_path, OUTPUT_FOLDER)
|
|
|
|
bid_homework_path, OUTPUT_FOLDER)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[{files:[out_file.file_path], count: 1, index: 1,
|
|
|
|
[{files:[out_file.file_path], count: 1, index: 1,
|
|
|
|
real_file: out_file.file_path, file: File.basename(out_file.file_path),
|
|
|
|
real_file: out_file.file_path,
|
|
|
|
|
|
|
|
file: File.basename(out_file.file_path),
|
|
|
|
|
|
|
|
base64file: Base64.encode64(File.basename(out_file.file_path)),
|
|
|
|
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
|
|
|
|
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
|
|
|
|
}]
|
|
|
|
}]
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -129,7 +140,9 @@ class ZipdownController < ApplicationController
|
|
|
|
bid_homework_path, OUTPUT_FOLDER)
|
|
|
|
bid_homework_path, OUTPUT_FOLDER)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[{files:[out_file.file_path], count: 1, index: 1,
|
|
|
|
[{files:[out_file.file_path], count: 1, index: 1,
|
|
|
|
real_file: out_file.file_path, file: File.basename(out_file.file_path),
|
|
|
|
real_file: out_file.file_path,
|
|
|
|
|
|
|
|
file: File.basename(out_file.file_path),
|
|
|
|
|
|
|
|
base64file: Base64.encode64(File.basename(out_file.file_path)),
|
|
|
|
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
|
|
|
|
size:(out_file.pack_size / 1024.0 / 1024.0).round(2)
|
|
|
|
}]
|
|
|
|
}]
|
|
|
|
end
|
|
|
|
end
|
|
|
|