I have a function that prints all the directories and subdirectories and files. Some of the directories are locked and I can't get in them so I can't print to the screen what is in them and I can't change the permission on the directory either, so what I get is an error that says;
Warning: ChDir: Permission denied (errno 13) in
Here is my code:
<?php
$basedir = "/home/"; // Base directory
function listall($dir)
{
// Initialize temporary arrays for sorting
$dir_files = $dir_subdirs = array();
// Print current directory
print( "<ul>");
print( "<li><b>$dir</b>\n");
// Change to directory
chdir($dir);
// Open directory;
$handle = @opendir($dir);
// or die( "Directory \"$dir\"not found.");
// Loop through all directory entries, construct
// two temporary arrays containing files and sub directories
while($entry = readdir($handle))
{
if(is_dir($entry) && $entry != ".." && $entry != ".")
{
$dir_subdirs[] = $entry;
}
elseif($entry != ".." && $entry != ".")
{
$dir_files[] = $entry;
}
}
// Sort files and sub directories
sort($dir_files);
sort($dir_subdirs);
// Print all files in the curent directory
for($i=0; $i<count($dir_files); $i++)
{
print( "<li>$dir_files[$i]\n");
}
// Traverse sub directories
for($i=0; $i<count($dir_subdirs); $i++)
{
listall( "$dir$dir_subdirs[$i]/");
}
print( "</ul>");
// Close directory
closedir($handle);
}
listall($basedir);
?>
so from what I can tell is that I would of calling the function like
listall($basedir);
instead I should do:
@listall($basedir); {
print (you can't get to this directory);
}
Thanks in advance for your help!
Heather