-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdir_listing.php
More file actions
executable file
·172 lines (141 loc) · 4.53 KB
/
dir_listing.php
File metadata and controls
executable file
·172 lines (141 loc) · 4.53 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
<!DOCTYPE html>
<html>
<head>
<!-- Bootstrap -->
<link href="/dirl/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
<![endif]-->
<!-- Icon -->
<link rel="icon" href="/dirl/favicon32.ico">
<title><?php echo $_SERVER['REQUEST_URI'] ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style type="text/css">
body {
padding-top: 60px;
}
</style>
</head>
<!--page content-->
<body>
<?php
require 'dir_listing_func.php';
include 'dir_listing_config.php';
//PATH
$path = $_SERVER['REQUEST_URI'];
$doc_root = $_SERVER['DOCUMENT_ROOT'];
//remove last '/' from doc_root if exist
if($doc_root[strlen($doc_root)-1]=='/')
$doc_root = substr($doc_root,0,strlen($doc_root)-1);
//Substitute %xx characters
$path = rawurldecode($path);
//Create full path
$full_path = $_SERVER['DOCUMENT_ROOT'].$path;
//END PATH
//BREADCRUMB
$folders=explode('/',$path);
$fathers=count($folders)-2;
echo " <div class='container navbar-fixed-top'>\n";
echo " <ol class='breadcrumb'>\n";
//fathers path
for($i=0;$i<$fathers;++$i){
echo " <li><a href='";
for($j=0;$j<($fathers-$i);++$j){
echo '../';
}
echo "'>".htmlentities($folders[$i])."</a></li>\n";
}
//this folder
echo " <li class='active'>".htmlentities($folders[$fathers])."</li>\n";
echo " </ol>\n";
echo " </div>\n";
//END_BREADCRUMB
//TABLE
$dir_handle = opendir($full_path);
//error opening folder
if($dir_handle == false){
echo "<br><br><div class='container'><div class='alert alert-danger text-center'><strong>Error!</strong> failed to open folder </div></div>\n";
exit('failed to open folder');
}
$folderlist = array();
$filelist = array();
while( false !== ($entry = readdir($dir_handle))){
//skip hidden files(optional), current folder ".", parent folder ".."
if ( ( strpos($entry,'.') === 0 and $show_hidden_files===false) | $entry == "." | $entry == ".." ){
continue;
}else if ( is_dir( $full_path.$entry ) ) {
$folderlist[] = $entry;
}else{
$filelist[] = $entry;
}
}
//order folder and files
sort($folderlist);
sort($filelist);
//foldere is empty
if(count ($folderlist) == 0 and count ($filelist) == 0){
echo '<br><br><div class="container"><div class="alert alert-info text-center"><strong>This folder is empty</strong></div></div>';
exit();
}
//print files table
//print header
echo'
<div class="container">
<table class="table table-condensed table-hover">
<thead>
<th width="35"></th>
<th class="text-primary">Name</th>
<th width="89" class="text-primary text-center">Dim</th>';
if($show_modified_time === true)
echo'
<th class="text-primary text-center">Last modified</th>';
echo'
</thead>';
//print folder
foreach ($folderlist as $val) {
echo '
<tr>
<td><span class="glyphicon glyphicon-folder-open"></span></td>
<td><a href="'.rawurlencode($val).'">'.htmlentities($val).'</td>';
if($use_du_command === true && $show_folders_size === true)
echo'
<td class="text-right">'. format_bytes(get_file_size($full_path.$val)) .'</td>';
else
echo'
<td class="text-center">-</td>';
if($show_modified_time === true)
echo'
<td></td>';
echo'
</tr>';
}
//print file
foreach ($filelist as $val) {
echo '
<tr>
<td><span class="glyphicon '.choose_icon($val).'"></span></td>
<td><a href="'.rawurlencode($val).'">'.htmlentities($val).'</td>
<td class="text-right">'. format_bytes(get_file_size($full_path.$val)) .'</td>';
if($show_modified_time === true)
echo'
<td class="text-center"><small>'.date("d/m/y H:i:s",filectime($full_path.$val)).'</small></td>';
echo '
</tr>';
}
echo '
</table>
</div>'."\n";
//end files table print
?>
<div class="container">
<p class="text-right"><a href="https://github.com/ael-code/dir-listing-bootstrap" class="text-muted"><small>Ael's php directory listing</small></a></p>
</div>
<!-- jQuery (necessary for Bootstrap's JavaScript plugins)-->
<script src="http://code.jquery.com/jquery.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="/dirl/bootstrap/js/bootstrap.min.js"></script>
</body>
</html>