Skip to content

Instantly share code, notes, and snippets.

@Phoenix616
Last active June 13, 2022 20:03
Show Gist options
  • Save Phoenix616/bebe402ded09215e1f279a70bdc96703 to your computer and use it in GitHub Desktop.
Save Phoenix616/bebe402ded09215e1f279a70bdc96703 to your computer and use it in GitHub Desktop.
Simple Directory List
<!--
Simple Directory List
Copyright (C) 2020 Max Lee aka Phoenix616 (max@themoep.de)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<title><?php echo $_SERVER['HTTP_HOST']; ?></title>
<style>
:root {
--border-radius: 4px;
--content-background-color: #ff9800;
--background-color: white;
--button-background-color: white;
--button-hover-background-color: #ececec;
--font-color: rgb(35, 33, 33);
--button-font-color: rgb(35, 33, 33);
}
@media (prefers-color-scheme: dark) {
:root {
--background-color: rgb(34, 36, 37);
--button-font-color: rgb(170, 170, 185);
--button-background-color: #262626;
--button-hover-background-color: rgb(35, 33, 33);
}
}
body {
color: var(--font-color);
background-color: var(--background-color);
font-family: Helvetica, arial, nimbussansl, liberationsans, freesans, clean, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
margin: 0;
}
h1 {
margin: 0;
}
.content {
margin-left: auto;
margin-right: auto;
max-width: 420px;
margin-top: 0;
padding: 10px;
background-color: var(--content-background-color);
border-radius: 0px 0px var(--border-radius) var(--border-radius);
}
.content a {
display: block;
padding: 6px 16px;
color: var(--font-color);
text-decoration: none;
}
a.entry {
margin-top: 10px;
padding: 12px 16px;
background-color: var(--button-background-color);
border-radius: var(--border-radius);
color: var(--button-font-color);
}
.entry:hover {
background-color: var(--button-hover-background-color);
}
.entry img {
height: 32px;
float: right;
margin-right: -12px;
margin-top: -7px;
}
</style>
<link rel='shortcut icon' href="favicon.ico" type="image/x-icon" />
</head>
<body>
<dir class="content"><?php
$dir = "*";
echo '<h1><a href="https://' . $_SERVER['HTTP_HOST'] . '">' . $_SERVER['HTTP_HOST'] . "</a></h1>\n";
foreach (glob($dir) as $file) {
if (is_dir($file)) {
echo ' <a class="entry" href="/' . $file .'/">';
if (file_exists(__DIR__ . '/' . $file . '.png')) {
echo '<img src="/' . $file . '.png">';
}
echo $file . "</a>\n";
}
}
?>
</dir>
</body>
</html>
@Phoenix616
Copy link
Author

Phoenix616 commented Sep 13, 2020

How to use:

Put list.php into a directory, make it the index (e.g. nginx' location index or by naming it index.php) and it will automatically generate a list from the available directories in that directory.

If you want icons to the entries add <entry name>.png files into the same directory that you added the php file in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment