PHP 目录列表不起作用



PHP 目录列表不起作用,我做错了什么?电影目录中有文件夹,但它们没有显示在我的输出中。

<?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);
?>

问题是当您检查$ourItem是否是一个文件夹时,您忘记了在当前目录中查找该文件夹。

见下文。

// 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);

最新更新