Skip to content

Instantly share code, notes, and snippets.

@smonteverdi
Created March 7, 2012 15:54
Show Gist options
  • Save smonteverdi/1993930 to your computer and use it in GitHub Desktop.
Save smonteverdi/1993930 to your computer and use it in GitHub Desktop.
PHP: List Files In Directory
function dirList ($directory) {
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// keep going until all files in directory have been read
while ($file = readdir($handler)) {
// if $file isn't this directory or its parent,
// add it to the results array
if ($file != '.' && $file != '..')
$results[] = $file;
}
// tidy up: close the handler
closedir($handler);
// done!
return $results;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment