Reputation: 428
PHP Directory listing is not working, what am I doing wrong?. There are folders in the movies directory, but they are not showing in my output.
<?php
// declare the folder
$ourDir = "movies";
// prepare to read directory contents
$ourDirList = @opendir($ourDir);
// loop through the items
while ($ourItem = readdir($ourDirList))
{
// check if it is a directory
if (is_dir($ourItem))
{
echo $ourItem;
echo "<br />";
}
}
closedir($ourDirList);
?>
Upvotes: 0
Views: 230
Reputation: 1073
issue is when you are checking if $ourItem is a folder, you are forgetting is looking in the current directory for the folder.
see below.
// declare the folder
$ourDir = "movies";
// prepare to read directory contents
$ourDirList = @opendir($ourDir);
// loop through the items
while ($ourItem = readdir($ourDirList))
{
// check if it is a directory
if (is_dir($ourDir.DIRECTORY_SEPARATOR.$ourItem) )
{
echo $ourItem;
echo "<br />";
}
}closedir($ourDirList);
Upvotes: 1