Skip to content

Instantly share code, notes, and snippets.

@GaryJones
Created February 12, 2012 13:25
Show Gist options
  • Save GaryJones/1808441 to your computer and use it in GitHub Desktop.
Save GaryJones/1808441 to your computer and use it in GitHub Desktop.
Recursive directory listing.
<?php
function recursive_dir_listing( $dir = '.', $maxlevel = 2, $level = 0 ) {
if ( $maxlevel == $level )
return;
$dirs = glob( $dir . '/*' , GLOB_ONLYDIR );
if ( ! $dirs )
return;
echo '<ul>';
foreach( $dirs as $subdir ) {
echo '<li><a href="' . str_replace( './', '', $subdir ) . '">' . str_replace( $dir . '/', '', $subdir ) . '</a> ';
recursive_dir_listing( $subdir, $maxlevel, $level + 1 );
echo '</li>';
}
echo '</ul>';
}
?><!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-gb" lang="en-gb">
<head>
<meta charset="UTF-8"/>
<title>Gary Jones: API Documentation for Projects</title>
</head>
<body>
<h1>Project API Documentation</h1>
<?php
recursive_dir_listing();
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment