Created
April 11, 2012 13:55
-
-
Save sercomi/2359452 to your computer and use it in GitHub Desktop.
PHP: Get directory list files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Obtiene la lista de archivos del directorio especificado | |
* @param string $directory | |
* @return array listado de archivos | |
*/ | |
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