实现代码如下所示:
1.主页面file_zip.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
<!DOCTYPE html>
<html>
<head>
<meta charset= "UTF-8" >
<title>文件管理</title>
<script src= "bootstrap/js/jquery-1.11.2.min.js" ></script>
</head>
<style>
*{ margin:0px auto; padding:0px}
#wai{ width:800px;}
.list{ width:50%; height:35px; background-color:#09F; margin-top:2px; color:white; font-weight:bold; text-align:left; line-height:35px; vertical-align:middle; font-size:28px; padding:5px}
.mulu{ background-color:#FC9}
.mulu:hover{ cursor:pointer}
#prev:hover{ cursor:pointer}
</style>
<body>
<div id= "outside" >
<?php
session_start();
$fname = "/wamp/www" ; //使$filename的值为根文件夹中www目录下的所有文件夹
if (! empty ( $_SESSION [ "lujing" ])){
$fname = $_SESSION [ "lujing" ]; //把session存储的路径赋值给$fname
echo "<div id='prev' class='list' lj='{sj}'>返回上一级</div>" ;
}
?>
<div id= "inside" >
<?php
$sj = dirname( $fname );
$dir = opendir( $fname );
$arr = array (); //将文件夹与文件合并放入
$arr1 = array (); //放入文件夹
$arr2 = array (); //放入文件
while ( $filename = readdir( $dir )){ //把$fname里面的所有内容遍历出来
if ( $filename != "." ){
$ml = $fname . "/" . $filename ;
if ( is_dir ( $ml )){
$arr1 [ ] = $ml ;
} else {
$arr2 [ ] = $ml ;
}
}
}
$arr = array_merge ( $arr1 , $arr2 );
foreach ( $arr as $v ){
$filename = basename ( $v );
if ( is_dir ( $v )){
echo "<div lj='{$ml}' class='list mulu'>{$filename}</div>" ;
} else {
echo "<div class='list'>{$filename}</div>" ;
}
}
closedir ( $dir );
?>
</div>
</div>
</body>
<script>
$( ".mulu" ).dblclick( function (){
var lj = $(this).attr( "lj" ); //取点击内容自己的属性值lj,lj里面存储的是点击的文件夹的目录
$.ajax({
url: "file_zip_chuli.php" ,
data:{lj:lj},
type: "POST" ,
dataType: "TEXT" ,
success: function (){
window.location.href = "file_zip.php" ;
}
});
})
$( "#prev" ).dblclick( function (){
Load();
})
//双击事件的方法
function Load(){
var lj = $(this).attr( "lj" );
$.ajax({
url: "file_zip_chuli.php" ,
data:{lj:lj},
type: "POST" ,
dataType: "TEXT" ,
success: function (){
window.location.href = "file_zip.php" ;
}
});
}
</script>
</html>
|
2.主页面的处理页面file_zip_chuli.php
1
|
<?php session_start(); $lj = $_POST [ "lj" ]; $_SESSION [ "lujing" ] = $lj ;
|
总结
以上所述是小编给大家介绍的PHP文件管理之实现网盘及压缩包的功能操作,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对服务器之家网站的支持!
原文链接:http://www.cnblogs.com/jly144000/archive/2017/09/20/7560283.html