Add file download function

This commit is contained in:
kyg516 2016-09-19 19:57:10 +09:00
parent bffd4d7cad
commit ab00afa513
4 changed files with 428 additions and 380 deletions

View File

@ -6,6 +6,16 @@ class HomeController < ApplicationController
file_directory(@current_dir)
end
def file_download
@file_name = params[:file_name]
puts "file_name: " + @file_name
if File.exist?(@file_name)
#File.delete(@file_name)
puts "file exist!!"
send_file(@file_name)
puts "send success"
end
end
def make_directory
current_dir = params[:current_dir]
@ -15,7 +25,6 @@ class HomeController < ApplicationController
redirect_to '/home/index'
end
def delete_file
file_name = params[:file_name]
puts "rm #{file_name} -rf"

View File

@ -7,7 +7,7 @@
</div>
<!-- create overlay page -->
<div id="popup_mkdir" class="overlay">
<div id="popup_mkdir" class="overlay">
<div class="popup">
<h2> Make Directory </h2>
<a class="close" href="#">&times;</a>
@ -37,8 +37,7 @@
</form>
</div>
</div>
</div>
<!-- page content -->
<div class="right_col" role="main">
@ -162,8 +161,12 @@
<a style="cursor: pointer" onclick="change_directory('<%=@current_dir + "/" + t["name"]%>')"> <%=t["name"]%></a>
</td>
<% else %>
<td><i class="fa fa-file-o"></i>
<a style="cursor: pointer"><%=t["name"]%></a>
<td>
<form class="form_file_download" data-parsley-validate>
<i class="fa fa-file-o"></i>
<input type="hidden", value="<%=@current_dir + '/' + t['name']%>">
<button type="submit" style="border: none; background: none;"><%=t["name"]%></button>
</form>
</td>
<% end %>
<td><%=t["auth"]%></td>
@ -183,15 +186,15 @@
</div>
<!-- /page content -->
<script type="text/javascript">
$(document).ready(function() {
<script type="text/javascript">
$(document).ready(function() {
$('#datatable').dataTable();
right_click();
});
</script>
<script>
});
</script>
<script>
function right_click(){
function right_click(){
/* right click */
$(".menuitem").mouseover(function(e){
var $el = $(this);
@ -214,9 +217,9 @@
CheckLocation();
return false;
});
}
}
$(".Del_dir").click(function(e){
$(".Del_dir").click(function(e){
$(location).attr('href', "#loading");
$.ajax({
method: "POST",
@ -229,18 +232,18 @@
})
$(".contextmenu").hide();
$(document).unbind('mousedown');
});
</script>
<!-- file manager functions -->
<script>
function change_upper(directory){
});
</script>
<!-- file manager functions -->
<script>
function change_upper(directory){
if(directory == "/") return;
var lastindex = directory.lastIndexOf("/");
if(lastindex == 0) lastindex++;
change_directory(directory.substring(0, lastindex));
}
}
function change_directory(directory){
function change_directory(directory){
$.ajax({
method: "POST",
url: "/application/changeDir",
@ -275,7 +278,13 @@
new_tr += "<td style='color:#0d8ade;' class='sorting_1'><i class='fa fa-folder-open-o'></i> ";
new_tr += "<a style='cursor: pointer' onclick='change_directory(" +'"' + cur + "/" + result.file[i].name +'"'+ ")'>" + result.file[i].name + "</a></td>";
}else{
new_tr += "<td><i class='fa fa-file-o'></i><a style='cursor: pointer'> " + result.file[i].name + "</a></td>";
new_tr += "<td>";
new_tr += "<form class='form_file_download' data-parsley-validate>";
new_tr += "<i class='fa fa-file-o'></i>";
new_tr += "<input type='hidden', value='" + cur + "/" + result.file[i].name + "'>";
new_tr += "<button type='submit' style='border: none; background: none;'>" + result.file[i].name + "</button>";
new_tr += "</form>";
new_tr += "</td>";
}
new_tr += "<td>"+result.file[i].auth+"</td>";
new_tr += "<td>"+result.file[i].size+"</td>";
@ -287,20 +296,50 @@
$("#table_div").append(new_table);
$('#datatable').dataTable();
right_click();
$(".form_file_download").submit(function(){
file_name = $(this).find("input").val();
$.ajax({
type: 'post',
url: '/file_download',
data: {file_name: file_name},
success: function(result){
console.log("post success");
}
});
return false;
})
}
})
}
</script>
</script>
<script>
$("document").ready(function(){
$(".form_file_download").submit(function(){
file_name = $(this).find("input").val();
$.ajax({
type: 'post',
url: '/file_download',
data: {file_name: file_name},
success: function(result){
console.log("post success");
}
});
return false;
})
});
</script>
<!--Test Page specific JS -->
<script type="text/javascript">
//alert ('Test Page specific JS')
$(function($) {
//alert ('Test Page specific JS')
$(function($) {
$(".knob").knob({
change: function(value) {
@ -352,25 +391,25 @@
return false;
}
}
});
});
// Example of infinite knob, iPod click wheel
var v, up = 0,
down = 0,
i = 0,
$idir = $("div.idir"),
$ival = $("div.ival"),
incr = function() {
// Example of infinite knob, iPod click wheel
var v, up = 0,
down = 0,
i = 0,
$idir = $("div.idir"),
$ival = $("div.ival"),
incr = function() {
i++;
$idir.show().html("+").fadeOut();
$ival.html(i);
},
decr = function() {
},
decr = function() {
i--;
$idir.show().html("-").fadeOut();
$ival.html(i);
};
$("input.infinite").knob({
};
$("input.infinite").knob({
min: 0,
max: 20,
stopper: false,
@ -396,6 +435,6 @@
}
v = this.cv;
}
});
});
});
});
</script>

View File

@ -44,7 +44,7 @@ Rails.application.configure do
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
# Specifies the header that your server uses for sending files.
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.

View File

@ -14,7 +14,7 @@ Rails.application.routes.draw do
get 'home/index' => 'home#index'
post 'home/mkdir' => 'home#make_directory'
post 'home/delete' => 'home#delete_file'
post 'file_download' => 'home#file_download'
#Volume
get 'volume/index' => 'volume#index'