Skip to content

Instantly share code, notes, and snippets.

@timjb
Created April 6, 2010 12:49
Show Gist options
  • Save timjb/357553 to your computer and use it in GitHub Desktop.
Save timjb/357553 to your computer and use it in GitHub Desktop.
<?php
// Parameter: &directory
if(!function_exists('outputDir')) {
function outputDir($dir) {
if(substr($dir, -1) != '/') {
$dir .= '/';
}
if(!is_dir($dir)) {
return $dir.' ist kein Verzeichnis!';
}
$output = '';
$files = scandir($dir);
if(count($files) > 2) {
$output .= '<ul>';
for($i = 0; $i < count($files); $i++) {
if($files[$i] === '.' || $files[$i] === '..') {
continue;
}
if(is_file($dir.$files[$i])) {
$output .= '<li><a class="filelink" href="'.$dir.$files[$i].'">'.$files[$i].'</a></li>';
} else if(is_dir($dir.$files[$i])) {
$output .= '<li>'.$files[$i];
$output .= outputDir($dir.$files[$i]);
$output .= '</li>';
}
}
$output .= '</ul>';
}
return $output;
}
}
return outputDir($directory);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment