Skip to content

Instantly share code, notes, and snippets.

@apphp-snippets
Created November 4, 2012 20:07
Show Gist options
  • Select an option

  • Save apphp-snippets/4013433 to your computer and use it in GitHub Desktop.

Select an option

Save apphp-snippets/4013433 to your computer and use it in GitHub Desktop.
This code allows to list the contents of any given directory.
<?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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment