I'm trying to read the contents of a directory and it's subdirectories. I
use w while loop with readdir($handle) and then an if statement with
filetype($file)=="dir" and that works that far. The contents of the
subdirectory is listed. After that breaks out of the if statement though,
the script goes back through the while loop and reads the next entry. The
problem is that the next file is a dir but the filetype function doesn't
return "dir", it returns nothing. I can only get through one subdirectory,
then all the other files in the main directory are listed even though they
are directories. Their contents are not displayed. I need to use the names
of the subdirectories for viewing and their locations. What is going wrong?

<snipet>
//sub directory function
function subdir($path, $root)
{
chdir($path);
$handle2=opendir(".");
$file2=readdir($handle2);
$file2=readdir($handle2);
while($file2=readdir($handle2))
{
?>
<tr bgcolor="<?php
if ($j%2==0)
echo "#FFFFFF";
else
echo "#FFFFcF";
?>">
<td><a href="http://www.wentworthco.com/shoponline/customerimages/<?php echo
$root."/".$file2;?>">[VIEW]</a></td>
<td><?php echo $file2;?></td>
<td><a href="deleteimage.php3?file=<?php echo $file2;?>&root=<?php
$root;?>">[DELETE]</a></td>
</tr>
<?
$j++;
}
}

$j=2;
chdir("/home/fpusers/booe/shoponline/customerimages/");
$handle=opendir(".");
$file=readdir($handle);
$file=readdir($handle);
while($file=readdir($handle))
{
if (filetype($file)=="dir")
{
subdir("/home/fpusers/booe/shoponline/customerimages/".$file."/", $file);
}
else {
?>
<tr bgcolor="<?php
if ($j%2==0)
echo "#FFFFFF";
else
echo "#FFFFcF";
?>">
<td><a href="http://www.wentworthco.com/shoponline/customerimages/<?php echo
$file;?>/">[VIEW]</a></td>
<td><?php echo $file;?></td>
<td><a href="deleteimage.php3?file=<?php $file;?>">[DELETE]</a></td>
<?
$j++;
}
}
</snipet>

Reply via email to