Skip to content

Instantly share code, notes, and snippets.

@ShahinSorkh
Last active June 1, 2019 06:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShahinSorkh/5b48fa727ea70e3256504e7cd3c198af to your computer and use it in GitHub Desktop.
Save ShahinSorkh/5b48fa727ea70e3256504e7cd3c198af to your computer and use it in GitHub Desktop.

Use this command in zsh to enable auto indexing:

for d in **/*(/); do ln "$PWD/index.php" "$d"; done

Run:

php -S 127.0.0.0 4747

And then check http://127.0.0.1:4747

<?php
# originated from http://stackoverflow.com/questions/14946964/ddg#14947054
# vim: ts=4 sw=4 sts=4 et sta ai si
$dir = substr(__DIR__,strlen($_SERVER['DOCUMENT_ROOT'])) ?: '/';
$g = array_diff(glob("*"), [basename(__FILE__)]);
usort($g,function($a,$b) {
if(is_dir($a) == is_dir($b))
return strnatcasecmp($a,$b);
else
return is_dir($a) ? -1 : 1;
});
?>
<h2>Index of <code><?= $dir ?></code></h2>
<?php if (empty($g)): ?>
<p>No files/directories in this directory</p>
<p><a href="..">back</a></p>
<?php else: ?>
<ul>
<li><?= implode("</li><li>",array_map(function($a) {$a=$a.(is_dir($a)?'/':''); return "<a href='$a'>$a</a>";},$g)) ?></li>
<?php if ($dir!='/'): ?><li><a href="..">------- back -------</a></li><?php endif ?>
</ul>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment