Hey all - still a newbie, real odd one here.
I've written the following function:
function dir_contents($directory)
{
$handle = opendir ($directory);
$file = readdir($handle);
$file = readdir($handle);
while ($file = readdir($handle))
{
// if (substr($file,0,1) == "-")
// {
echo "<p>Is <b>'".$file."'</b> a directory? ".is_dir($file)."</p>";
if (is_dir($file) == 1 )
{
echo "<p><b>Directory:".$file."</b><i>".$directory."</i></p>\n";
dir_contents($file);
}
else
{
echo "<p>".$file."</p>\n";
}
// }
}
closedir($handle);
}
which is supposed to do a directory listing. the idea is that it checks if the file its looking at is a directory, and if it is then it goes into that and lists the files in there too.
Firstly, when i ran it in one of my directories it worked nicely, except that it didnt go any further in than one level - it thought that the sub sub directories were files. so then i fed it the sub directory to start with , and it still thinks that the directory is a file! If i do a is_dir() for the directory at the end of the document then it does return a value of 1, so it knows really that it is a directory, but wont run the script on it!
Is there something wrong with what i've done above? you can see various lines I've put in and then taken out to try to get it to work, but I cant figure it out.
Many thanks in advance