-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirtable.php
125 lines (111 loc) · 3.38 KB
/
dirtable.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
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
<?php
/*
* File: dirtable.php
* Desc: Embedable directory listing table
* Auth: sumkittehz.codes
* Date: 2023-06-07 / Modified: 2023-06-16
*/
/*
* Define some field widths for the directory output listing
*/
$fldwid = array
(
'bytes' => "12", /* 12 digits for file size in bytes */
'perms' => "4", /* 4 digits for permissions */
'times' => "16", /* 16 characters for date & time */
'names' => "", /* filename width is not defined */
);
/* Create printf() style format string for dir fld output
*/
$fmtstr =
"%".$fldwid['bytes']."s ".
"%".$fldwid['times']."s ".
"%".$fldwid['names']."s\n";
/* Set the caption text to be display above the listing table:
*/
$caption_text = "Directory listing of " . getcwd() ;
/* prime the output array with the opening tags for the <div>
* container element, the <table> element, and the <caption> element.
*/
$output_lines = array ();
$output_lines[] = ' <div style="overflow-x:auto;">' ."\n";
$output_lines[] = ' <table class="dirlisting">' ."\n";
$output_lines[] = " <caption>$caption_text</caption>\n";
$datefmtstr = "Ymd:His"; /* date format string */
$cwd = getcwd(); /* get name of current working dir */
$files = scandir($cwd); /* get the list files */
/* Filter out hidden files & any other files we don't want to see
*/
$result = preg_grep
(
'/^\./',$files, PREG_GREP_INVERT
);
/* For each filename that got through the filter, make a table row
* entry for the file.
*/
foreach($result as $fn)
{
if ( is_dir($fn) )
{
/* handle directory links differently - create a link the
* sub-directory, add sub-directory link to a table-cell
* element - only provide links to sub-directories listed
* here; these directories must have an INDEX file in order
* to display correctly on the W3 Spaces -hosted site.
*/
if
(!(
$fn === "mud" ||
$fn === "Images" ||
$fn === "FlexBoxEx" ||
$fn === "voice-change-o-matic" ||
$fn === "webaudio-examples-main" ||
$fn === "template" ||
$fn === "gallery-ex" ||
$fn === "Documentation" ||
$fn === "Audio" ||
$fn === "SVG" ||
$fn === "Clocks"
))
{
continue;
}
/*
* Add the trailing slash to the dirname here
*/
$fn .= '/';
}
if ( preg_match('/.+~$/',$fn) )
{
/* filter out backup files */
continue;
}
/*
* Get the last modification time for $fn
*/
$ctime_str = date( $datefmtstr, filectime($fn) );
/*
* Create the <time> element as a string
*/
$time_elem = '<time datetime="' . $ctime_str . '">'
. $ctime_str
. '</time>';
$anch_elem = '<a class="fn" target="_blank" href="./' . $fn . '">'
. $fn . '</a>';
/* Add aline to the output
*/
$output_lines[] = "<tr><th>$time_elem</th><td>$anch_elem</td></tr>\n";
}
/* Close the table and its containing </div> element
*/
$output_lines[] = '
</table>
</div>
';
/* Output the accumulated output lines
*/
foreach ($output_lines as $ln)
{
echo $ln;
}
?>