Add file download function
This commit is contained in:
parent
bffd4d7cad
commit
ab00afa513
@ -6,6 +6,16 @@ class HomeController < ApplicationController
|
|||||||
file_directory(@current_dir)
|
file_directory(@current_dir)
|
||||||
end
|
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
|
def make_directory
|
||||||
current_dir = params[:current_dir]
|
current_dir = params[:current_dir]
|
||||||
@ -15,7 +25,6 @@ class HomeController < ApplicationController
|
|||||||
redirect_to '/home/index'
|
redirect_to '/home/index'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
def delete_file
|
def delete_file
|
||||||
file_name = params[:file_name]
|
file_name = params[:file_name]
|
||||||
puts "rm #{file_name} -rf"
|
puts "rm #{file_name} -rf"
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- create overlay page -->
|
<!-- create overlay page -->
|
||||||
<div id="popup_mkdir" class="overlay">
|
<div id="popup_mkdir" class="overlay">
|
||||||
<div class="popup">
|
<div class="popup">
|
||||||
<h2> Make Directory </h2>
|
<h2> Make Directory </h2>
|
||||||
<a class="close" href="#">×</a>
|
<a class="close" href="#">×</a>
|
||||||
@ -37,8 +37,7 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<!-- page content -->
|
<!-- page content -->
|
||||||
<div class="right_col" role="main">
|
<div class="right_col" role="main">
|
||||||
@ -162,8 +161,12 @@
|
|||||||
<a style="cursor: pointer" onclick="change_directory('<%=@current_dir + "/" + t["name"]%>')"> <%=t["name"]%></a>
|
<a style="cursor: pointer" onclick="change_directory('<%=@current_dir + "/" + t["name"]%>')"> <%=t["name"]%></a>
|
||||||
</td>
|
</td>
|
||||||
<% else %>
|
<% else %>
|
||||||
<td><i class="fa fa-file-o"></i>
|
<td>
|
||||||
<a style="cursor: pointer"><%=t["name"]%></a>
|
<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>
|
</td>
|
||||||
<% end %>
|
<% end %>
|
||||||
<td><%=t["auth"]%></td>
|
<td><%=t["auth"]%></td>
|
||||||
@ -183,15 +186,15 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- /page content -->
|
<!-- /page content -->
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
$('#datatable').dataTable();
|
$('#datatable').dataTable();
|
||||||
right_click();
|
right_click();
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
function right_click(){
|
function right_click(){
|
||||||
/* right click */
|
/* right click */
|
||||||
$(".menuitem").mouseover(function(e){
|
$(".menuitem").mouseover(function(e){
|
||||||
var $el = $(this);
|
var $el = $(this);
|
||||||
@ -214,9 +217,9 @@
|
|||||||
CheckLocation();
|
CheckLocation();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
$(".Del_dir").click(function(e){
|
$(".Del_dir").click(function(e){
|
||||||
$(location).attr('href', "#loading");
|
$(location).attr('href', "#loading");
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
@ -229,18 +232,18 @@
|
|||||||
})
|
})
|
||||||
$(".contextmenu").hide();
|
$(".contextmenu").hide();
|
||||||
$(document).unbind('mousedown');
|
$(document).unbind('mousedown');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
<!-- file manager functions -->
|
<!-- file manager functions -->
|
||||||
<script>
|
<script>
|
||||||
function change_upper(directory){
|
function change_upper(directory){
|
||||||
if(directory == "/") return;
|
if(directory == "/") return;
|
||||||
var lastindex = directory.lastIndexOf("/");
|
var lastindex = directory.lastIndexOf("/");
|
||||||
if(lastindex == 0) lastindex++;
|
if(lastindex == 0) lastindex++;
|
||||||
change_directory(directory.substring(0, lastindex));
|
change_directory(directory.substring(0, lastindex));
|
||||||
}
|
}
|
||||||
|
|
||||||
function change_directory(directory){
|
function change_directory(directory){
|
||||||
$.ajax({
|
$.ajax({
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "/application/changeDir",
|
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 += "<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>";
|
new_tr += "<a style='cursor: pointer' onclick='change_directory(" +'"' + cur + "/" + result.file[i].name +'"'+ ")'>" + result.file[i].name + "</a></td>";
|
||||||
}else{
|
}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].auth+"</td>";
|
||||||
new_tr += "<td>"+result.file[i].size+"</td>";
|
new_tr += "<td>"+result.file[i].size+"</td>";
|
||||||
@ -287,20 +296,50 @@
|
|||||||
$("#table_div").append(new_table);
|
$("#table_div").append(new_table);
|
||||||
$('#datatable').dataTable();
|
$('#datatable').dataTable();
|
||||||
right_click();
|
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 -->
|
<!--Test Page specific JS -->
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|
||||||
//alert ('Test Page specific JS')
|
//alert ('Test Page specific JS')
|
||||||
$(function($) {
|
$(function($) {
|
||||||
|
|
||||||
$(".knob").knob({
|
$(".knob").knob({
|
||||||
change: function(value) {
|
change: function(value) {
|
||||||
@ -352,25 +391,25 @@
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Example of infinite knob, iPod click wheel
|
// Example of infinite knob, iPod click wheel
|
||||||
var v, up = 0,
|
var v, up = 0,
|
||||||
down = 0,
|
down = 0,
|
||||||
i = 0,
|
i = 0,
|
||||||
$idir = $("div.idir"),
|
$idir = $("div.idir"),
|
||||||
$ival = $("div.ival"),
|
$ival = $("div.ival"),
|
||||||
incr = function() {
|
incr = function() {
|
||||||
i++;
|
i++;
|
||||||
$idir.show().html("+").fadeOut();
|
$idir.show().html("+").fadeOut();
|
||||||
$ival.html(i);
|
$ival.html(i);
|
||||||
},
|
},
|
||||||
decr = function() {
|
decr = function() {
|
||||||
i--;
|
i--;
|
||||||
$idir.show().html("-").fadeOut();
|
$idir.show().html("-").fadeOut();
|
||||||
$ival.html(i);
|
$ival.html(i);
|
||||||
};
|
};
|
||||||
$("input.infinite").knob({
|
$("input.infinite").knob({
|
||||||
min: 0,
|
min: 0,
|
||||||
max: 20,
|
max: 20,
|
||||||
stopper: false,
|
stopper: false,
|
||||||
@ -396,6 +435,6 @@
|
|||||||
}
|
}
|
||||||
v = this.cv;
|
v = this.cv;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
@ -44,7 +44,7 @@ Rails.application.configure do
|
|||||||
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
|
# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb
|
||||||
|
|
||||||
# Specifies the header that your server uses for sending files.
|
# 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
|
# 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.
|
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
|
||||||
|
@ -14,7 +14,7 @@ Rails.application.routes.draw do
|
|||||||
get 'home/index' => 'home#index'
|
get 'home/index' => 'home#index'
|
||||||
post 'home/mkdir' => 'home#make_directory'
|
post 'home/mkdir' => 'home#make_directory'
|
||||||
post 'home/delete' => 'home#delete_file'
|
post 'home/delete' => 'home#delete_file'
|
||||||
|
post 'file_download' => 'home#file_download'
|
||||||
|
|
||||||
#Volume
|
#Volume
|
||||||
get 'volume/index' => 'volume#index'
|
get 'volume/index' => 'volume#index'
|
||||||
|
Loading…
Reference in New Issue
Block a user