Skip to content

Instantly share code, notes, and snippets.

@codearmorygists
Created September 19, 2012 23:18
Show Gist options
  • Save codearmorygists/3752980 to your computer and use it in GitHub Desktop.
Save codearmorygists/3752980 to your computer and use it in GitHub Desktop.
PHP list all files in directory
<?php
function getDirectoryList ($directory) {
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// open directory and walk through the filenames
while ($file = readdir($handler)) {
// if file isn't this directory or its parent, add it to the results
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