I got this code for traversing a directory, see below.
My problem is that some directories are read only. On those read only directories, such as this one, /home/mom/
I get the error:
Warning: ChDir: Permission denied (errno 13) in /home//myhosting.net/hd/traverse_directory.phtml on line 16
followed by:
Warning: unable to find identifier (0) in /home/httpd/myhosting.net/hd/traverse_directory.phtml on line 24
<?php
$basedir = "/home/"; // Base directory
function listall($dir)
{
// Initialize temporary arrays for sorting
$dir_files = $dir_subdirs = array();
<?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);
?>
//
Any and all assistance is appreciated.
Kind Regards and Happy Holidays,
Heather