Skip to content

Instantly share code, notes, and snippets.

@vgrovestine
Last active July 25, 2023 14:05
Show Gist options
  • Save vgrovestine/af47f512efe6fe0611836717ca237372 to your computer and use it in GitHub Desktop.
Save vgrovestine/af47f512efe6fe0611836717ca237372 to your computer and use it in GitHub Desktop.
Simple utility to browse the contents of a filesystem provided a starting path: Handy as a workaround for (Apache HTTPd) "Options -Indexes" directives and "mod_rewrite" shenanigans.
<!DOCTYPE html>
<html>
<head>
<title>Filesystem Browser</title>
<style>
body, input {
font-family: monospace;
font-size: 16px;
}
body {
background-color: #f9f9f9;
color: #111;
line-height: 1.375em;
padding: 1em 2em 2em 2em;
}
input[type="text"] {
width: 40em;
max-width: 90%;
}
ol li::marker {
font-size: 0.75em;
color: #777;
}
ol li a.directory {
font-weight: bold;
}
ol li a.file {
font-weight: normal;
}
a {
text-decoration: none;
color: #00b;
}
a:visited {
color: #006;
}
a:active,
a:hover {
color: #b00;
}
</style>
</head>
<body>
<h1>Filesystem Browser</h1>
<h2>Path</h2>
<?php
$path = (array_key_exists('path', $_GET) ? urldecode($_GET['path']) : '');
if(empty($path)) {
$path = '.';
}
$path = preg_replace('/(\/+)/', '/', $path . '/');
?>
<form action="#" method="get">
<input type="text" name="path" value="<?php echo $path; ?>">
<input type="submit" value="Retrieve">
</form>
<h2>Absolute</h2>
<p><?php echo realpath($path); ?></p>
<h2>Contents</h2>
<?php
$glob = glob($path . '*', GLOB_MARK);
if(empty($glob)) {
echo '<p>Error: No such path on this filesystem</p>';
}
else {
echo '<ol>';
foreach($glob as $g) {
echo '<li>';
if(is_dir($g)) {
echo '<a class="directory" href="?path=' . urlencode($g) . '">';
}
else {
echo '<a class="file" href="' . $g . '">';
}
echo str_replace($path, '', $g). '</a></li>';
}
echo '</ol>';
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment