1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| function scanDirectories($rootDir) {
// set filenames invisible if you want
$invisibleFileNames = array(".", "..", ".htaccess", ".htpasswd");
// run through content of root directory
$dirContent = scandir($rootDir);
$allData = array();
// file counter gets incremented for a better
$fileCounter = 0;
foreach($dirContent as $key => $content) {
// filter all files not accessible
$path = $rootDir.'/'.$content;
if(!in_array($content, $invisibleFileNames)) {
// if content is file & readable, add to array
if(is_file($path) && is_readable($path)) {
$tmpPathArray = explode("/",$path);
// saving filename
$allData[$fileCounter]['fileName'] = end($tmpPathArray);
// saving while path (for better access)
$allData[$fileCounter]['filePath'] = $path;
// get file extension
$filePartsTmp = explode(".", end($tmpPathArray));
$allData[$fileCounter]['fileExt'] = end($filePartsTmp);
// get file date
$allData[$fileCounter]['fileDate'] = filectime($path);
// get filesize in byte
$allData[$fileCounter]['fileSize'] = filesize($path);
$fileCounter++;
// if content is a directory and readable, add path and name
}elseif(is_dir($path) && is_readable($path)) {
$dirNameArray = explode('/',$path);
$allData[$path]['dirPath'] = $path;
$allData[$path]['dirName'] = end($dirNameArray);
// recursive callback to open new directory
$allData[$path]['content'] = scanDirectories($path);
}
}
}
return $allData;
} |
Partager