Last active
April 17, 2016 23:03
-
-
Save mccreath/58cb17237a32a9f9be7d to your computer and use it in GitHub Desktop.
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
function getFileList($dir, $recurse=false) { | |
# array to hold return value and an edit | |
$retval = array(); | |
# add trailing slash if missing | |
if(substr($dir, -1) != "/") $dir .= "/"; | |
# open pointer to directory and read list of files | |
$d = @dir($dir) or die("getFileList: Failed opening directory $dir for reading"); | |
while(false !== ($entry = $d->read())) { | |
# skip hidden files | |
if($entry[0] == ".") continue; | |
if(is_dir("$dir$entry")) { | |
$retval[] = array( | |
"name" => "$dir$entry/", | |
"type" => filetype("$dir$entry"), | |
"size" => 0, | |
"lastmod" => filemtime("$dir$entry") | |
); | |
if($recurse && is_readable("$dir$entry/")) { | |
$retval = array_merge($retval, getFileList("$dir$entry/", true)); | |
} | |
} elseif(is_readable("$dir$entry")) { | |
$retval[] = array( | |
"name" => "$dir$entry", | |
"type" => mime_content_type("$dir$entry"), | |
"size" => filesize("$dir$entry"), | |
"lastmod" => filemtime("$dir$entry") | |
); | |
} | |
} | |
$d->close(); | |
return $retval; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment