DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
List Directory Contents in PHP
<?php
/* Source: http://www.apphp.com/index.php?snippet=php-list-directory-contents */
function list_directory_content($dir){
if(is_dir($dir)){
if($handle = opendir($dir)){
while(($file = readdir($handle)) !== false){
if($file != '.' && $file != '..' && $file != '.htaccess'){
echo '<a target="_blank" href="'.$dir.$file.'">'.$file.'</a><br>'."\n";
}
}
closedir($handle);
}
}
}
?>
This code allows to list the contents of any given directory.




