2017-07-30 10 views
0

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

php''のerror_reporting(E_ALL)を追加;?ini_set( 'はdisplay_errors'、1); 'とopendir''から '@'を削除し、再度 –

+0

をあなたのスクリプトを実行して確認してください、私はあなたを試してみました提案。私はエラーはなく、まだディレクトリリストはありません。ムービーフォルダはPHPスクリプトと同じディレクトリにあります(ムービーフォルダ内に空のフォルダが2つあります)。 – dreadycarpenter

+0

'movies'フォルダのアクセス許可を確認してください(077にする必要があります) –

答えて

1

問題は$ 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); 
関連する問題