Question

I tried loading the names of the files in the Books directory, with the following code:

<?php

  if ($handle = opendir('/Books')) {
    echo "Directory handle: $handle\n";
    echo "Entries:\n";

    while (false !== ($entry = readdir($handle))) {
      echo "$entry\n";
    }
 closedir($handle);
 }
?>

But it seems not to display the names. Am I doing this wrong or not locating the right directory?

Was it helpful?

Solution

Seems as if you're using the wrong directory... I think the Books folder is in the same directory as your script?

Then use only opendir('Books') which is a relative path to the directory.

When you use /Books you use the Books folder located in the root directory of your filesystem. (this is called an absolute path)

OTHER TIPS

I guess I would use scandir() for this one:

<?php  
$scanner = scandir("theFolder");  
foreach ($scanner as $fileName) {  
    echo "$fileName<br>";  
}  
?> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top