forked from helloxz/zdir
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
262 lines (241 loc) · 8.42 KB
/
Copy pathindex.php
File metadata and controls
262 lines (241 loc) · 8.42 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<?php
error_reporting(E_ALL^E_NOTICE^E_WARNING^E_DEPRECATED);
//载入配置文件
include_once("./config.php");
//载入zdir类
include_once("./functions/zdir.class.php");
@$admin = $_GET['admin'];
//获取当前目录
$thedir = __DIR__;
$i = 0;
//获取目录
$dir = $_GET['dir'];
//获取markdown文件地址
//echo $readme;
//对目录进行过滤
if((stripos($dir,'./')) || (stripos($dir,'.\\'))){
echo '非法请求!';
exit;
}
//分割字符串
$navigation = explode("/",$dir);
if(($dir == '') || (!isset($dir))) {
$listdir = scandir($thedir);
$readme = $thedir.'/readme.md';
}
else{
$listdir = scandir($thedir."/".$dir);
$readme = $thedir."/".$dir.'/readme.md';
}
$readme = str_replace('\\','/',$readme);
//计算上级目录
function updir($dir){
//分割目录
$dirarr = explode("/",$dir);
$dirnum = count($dirarr);
#var_dump($dirarr);
if($dirnum == 2) {
$updir = 'index.php';
}
else{
$updir = '';
for ( $i=1; $i < ($dirnum - 1); $i++ )
{
$next = $i + 1;
$updir = $updir.'/'.$dirarr[$i];
}
$updir = 'index.php?dir='.$updir;
}
return $updir;
}
#echo updir($dir);
$updir = updir($dir);
?>
<?php
//载入页头
include_once("./template/header.php")
?>
<!--面包屑导航-->
<div id="navigation" class = "layui-hide-xs">
<div class="layui-container">
<div class="layui-row">
<div class="layui-col-lg12">
<p>
当前位置:<a href="./">首页</a>
<!--遍历导航-->
<?php foreach( $navigation as $menu )
{
$remenu = $remenu.'/'.$menu;
if($remenu == '/'){
$remenu = $menu;
}
?>
<a href="./index.php?dir=<?php echo $remenu; ?>"><?php echo $menu; ?></a> /
<?php } ?>
</p>
</div>
<!--使用说明-->
<!--<div class="layui-col-lg12" style = "margin-top:1em;">
<div class="layui-collapse">
<div class="layui-colla-item">
<h2 class="layui-colla-title">使用说明(必看)</h2>
<div class="layui-colla-content">
<iframe src="<?php echo './functions/viewmd.php?file='.$readme; ?>" width="100%" height="600px" name="" frameborder = "0" align="middle"></iframe>
</div>
</div>
</div>
</div>-->
<!--使用说明END-->
</div>
</div>
</div>
<!--面包屑导航END-->
<!--遍历目录-->
<div id="list">
<div class="layui-container">
<div class="layui-row">
<div class="layui-col-lg12">
<table class="layui-table" lay-skin="line">
<colgroup>
<col width="400">
<col width="200">
<col width="200">
<col width="180">
<col>
</colgroup>
<thead>
<tr>
<th>文件名</th>
<th class = "layui-hide-xs"></th>
<th class = "layui-hide-xs">修改时间</th>
<th>文件大小</th>
<th class = "layui-hide-xs">操作</th>
</tr>
</thead>
<tbody>
<?php foreach( $listdir as $showdir ) {
//防止中文乱码
//$showdir = iconv('gb2312' , 'utf-8' , $showdir );
$fullpath = $thedir.'/'.$dir.'/'.$showdir;
$fullpath = str_replace("\\","\/",$fullpath);
$fullpath = str_replace("//","/",$fullpath);
//获取文件修改时间
$ctime = filemtime($fullpath);
$ctime = date("Y-m-d H:i",$ctime);
//搜索忽略的目录
if(array_search($showdir,$ignore)) {
continue;
}
//判读文件是否是目录,当前路径 + 获取到的路径 + 遍历后的目录
if(is_dir($thedir.'/'.$dir.'/'.$showdir)){
$suffix = '';
//设置上级目录
if($showdir == '..'){
$url = $updir;
}
else{
$url = "./index.php?dir=".$dir.'/'.$showdir;
}
$ico = "fa fa-folder-open";
$fsize = '-';
//返回类型
$type = 'dir';
}
//如果是文件
if(is_file($fullpath)){
//获取文件后缀
$suffix = explode(".",$showdir);
$suffix = end($suffix);
$url = '.'.$dir.'/'.$showdir;
//根据不同后缀显示不同图标
$ico = $zdir->ico($suffix);
//获取文件大小
$fsize = filesize($fullpath);
$fsize = ceil ($fsize / 1024);
if($fsize >= 1024) {
$fsize = $fsize / 1024;
$fsize = round($fsize,2).'MB';
}
else{
$fsize = $fsize.'KB';
}
$type = 'file';
#$info = "<a href = ''><i class='fa fa-info-circle' aria-hidden='true'></i></a>";
}
//其它情况,可能是中文目录
else{
$suffix = '';
//设置上级目录
if($showdir == '..'){
$url = $updir;
}
else{
$url = "./index.php?dir=".$dir.'/'.$showdir;
}
$ico = "fa fa-folder-open";
$fsize = '-';
$type = 'dir';
}
$i++;
?>
<tr id = "id<?php echo $i; ?>">
<td>
<!--判断文件是否是图片-->
<?php if(($suffix == 'jpg') || ($suffix == 'jpeg') || ($suffix == 'png') || ($suffix == 'gif') || ($suffix == 'bmp')){
?>
<a href="<?php echo $url ?>" id = "url<?php echo $i; ?>" onmouseover = "showimg(<?php echo $i; ?>,'<?php echo $url; ?>')" onmouseout = "hideimg(<?php echo $i; ?>)"><i class="<?php echo $ico; ?>"></i> <?php echo $showdir; ?></a>
<div class = "showimg" id = "show<?php echo $i; ?>"><img src="" id = "imgid<?php echo $i; ?>"></div>
<?php }else{ ?>
<a href="<?php echo $url ?>" id = "url<?php echo $i; ?>"><i class="<?php echo $ico; ?>"></i> <?php echo $showdir; ?></a>
<?php } ?>
</td>
<td id = "info" class = "layui-hide-xs">
<!--如果是readme.md-->
<?php if(($showdir == 'README.md') || ($showdir == 'readme.md')){ ?>
<a class = "layui-btn layui-btn-xs" href="javascript:;" onclick = "newmd('<?php echo $fullpath; ?>')" title = "点此查看使用说明">使用说明</a>
<!--视频播放器-->
<?php }elseif($zdir->video($url)){
?>
<a class = "layui-btn layui-btn-xs" href="javascript:;" onclick = "video('<?php echo $url ?>')">播放</a>
<!-- office在线预览 -->
<?php }elseif($zdir->office($url)){
?>
<a class = "layui-btn layui-btn-xs" href="javascript:;" onclick = "office('<?php echo $url ?>')">预览</a>
<!--文档查看器-->
<?php }elseif($zdir->is_text($url)){
?>
<a class = "layui-btn layui-btn-xs" href="javascript:;" onclick = "viewtext('<?php echo $fullpath; ?>')">查看</a>
<?php } ?>
<!--如果是文件-->
<?php if($type == 'file'){ ?>
<a href="javascript:;" title = "查看文件hash" onclick = "filehash('<?php echo $showdir; ?>','<?php echo $fullpath; ?>')"><i class="fa fa-info-circle" aria-hidden="true"></i></a>
<a href="javascript:;" onclick = "qrcode('<?php echo $showdir; ?>','<?php echo $url; ?>')" title = "显示二维码"><i class="fa fa-qrcode" aria-hidden="true"></i></a>
<?php } ?>
</td>
<td class = "layui-hide-xs"><?php echo $ctime; ?></td>
<td><?php echo $fsize; ?></td>
<td class = "layui-hide-xs">
<?php if($fsize != '-'){ ?>
<a href="javascript:;" class = "layui-btn layui-btn-xs" onclick = "copy('<?php echo $url ?>')">复制</a>
<?php } ?>
<!--如果是管理模式-->
<?php if((isset($admin)) && ($fsize != '-')) { ?>
<a href="javascript:;" class = "layui-btn layui-btn-xs layui-btn-danger" onclick = "delfile(<?php echo $i; ?>,'<?php echo $showdir; ?>','<?php echo $fullpath; ?>')">删除</a>
<?php } ?>
<!--如果是markdown文件-->
<?php if(($suffix == 'md') && ($suffix != null)){ ?>
<a href="javascript:;" onclick = "newmd('<?php echo $fullpath; ?>')" title = "点击查看"><i class="fa fa-eye fa-lg"></i></a>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<?php
//载入页脚
include_once("./template/footer.php")
?>