note 93547 deleted from function.opendir by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 11:16:56 +0000 |
| Subject: | note 93547 deleted from function.opendir by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197069@lists.php.net to get a copy of this message | ||
Note Submitter: jamon at clearsightdesign dot com
----
Another take on olivernasser's function below. I find this one slightly easier to understand.
<?php
// file_array() by Jamon Holmgren. Exclude files by putting them in the $exclude
// string separated by pipes. Returns an array with filenames as strings.
function file_array($path, $exclude = ".|..", $recursive = false) {
$path = rtrim($path, "/") . "/";
$folder_handle = opendir($path);
$exclude_array = explode("|", $exclude);
$result = array();
while(false !== ($filename = readdir($folder_handle))) {
if(!in_array(strtolower($filename), $exclude_array)) {
if(is_dir($path . $filename . "/")) {
if($recursive) $result[] = file_array($path, $exclude, true);
} else {
$result[] = $filename;
}
}
}
return $result;
}
?>