Here is my Code :::

 <?php

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


            while (false !== ($entry = readdir($handle))) {
                echo "$entry\n";?><br/>
            <?php }

            /* This is the WRONG way to loop over the directory. */
            while ($entry = readdir($handle)) {
                echo "$entry\n";
            }

            closedir($handle);
        }
  ?>

Output : login.php

loop1.php
My Music
My Pictures
note.xml
saveeditor.php
select.php 

In this listing MY Music is folder but i did not open the folder.... Any solution for this particular problem.... 

Recommended Answers

All 7 Replies

Each new folder, you want to list the contents of, needs to opened with opendir as well. It's a recursive function.

function my_opendir($dir) {
  if ($handle = opendir($dir)) {
    echo "<ul>Directory handle: $dir<br />Entries:";

    while (false !== ($entry = readdir($handle))) {
      if($entry=="."||$entry=="..") { continue; }
      echo "<li>";
      if(is_dir($dir.$entry)) { my_opendir($dir.$entry); }
      else { echo $entry; }
      echo "</li>";
      }
    echo "</ul>";

    closedir($handle);
    }
  }

@AndrisP :: Thaxs... Bur when when i click on particular folder then and then only open this folder ...

Hi..
How to click any file or folder in dirtectory listing ?
Any Solytion for this ?

in line 9 print entry as link, like: "<a href="".$entry."">".$entry."</a>"

Hello i want open only folder in directory listing not a file ?
There is any script avaiable in php ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.