i am creating some code that will read all directories from a "galleries" folder and put the paths into an xml file. the server is windows and php 5. now, the code below works when placed in a sub dir of the web root, but does not work from the web root itself, the dirs are not listed in the xml. can anybody help me figure out what im doing wrong? im stuck!
<?php
echo "<menu>\n";
function scan_directory_recursively($directory = 'galleries', $filter=TRUE){
// if the path has a slash at the end we remove it here
if(substr($directory,-1) == '/'){
$directory = substr($directory,0,-1);
}
// if the path is not valid or is not a directory ...
if(!file_exists($directory) || !is_dir($directory)){
// ... we return false and exit the function
return FALSE;
// ... else if the path is readable
}elseif(is_readable($directory)){
// we open the directory
$directory_list = opendir($directory);
// and scan through the items inside
while (FALSE !== ($file = readdir($directory_list))){
// if the filepointer is not the current directory
// or the parent directory
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//For any directory you do not want the side menu to scan simply add this:
// $file != 'DONT SCAN FOLDER NAME'
/////////////////////////////////////////////////////////////////////////////
if($file != '.' && $file != '..' && $file != 'pages' && $file != 'content'){
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// we build the new path to scan
$path = $directory.'/'.$file;
// if the path is readable
if(is_readable($path)){
// we split the new path by directories
$subdirectories = explode('/',$path);
// if the new path is a directory
if(is_dir($path)){
// add the directory details to the file list
$directory_tree[] = array(
'cat' => end($subdirectories),
// we scan the new path by calling this function
'subs' => scan_directory_recursively($path, $filter));
// if the new path is a file
}
}
}
}
// close the directory
closedir($directory_list);
// return file list
return $directory_tree;
// if the path is not readable ...
}else{
// ... we return false
return FALSE;
}
}
// ------------------------------------------------------------
$rf = scan_directory_recursively();
asort($rf);
foreach ($rf as $key=>$value) {
echo "<category Name=\"$value[cat]\" dirName=\"\">\n";
if(is_array($value['subs'])){
$newar = count($value['subs']);
$newarr = $value['subs'];
asort($newarr);
foreach ($newarr as $ok) {
echo "<subcat Name=\"$ok[cat]\" dirName=\"\"/>\n";
}
} else {
//echo "Key: $key; Value: $value<br />\n";
}
echo "</category>\n";
}
echo "</menu>\n";
?>