0

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.... 
3
Contributors
7
Replies
45
Views
3 Years
Discussion Span
Last Post by AndrisP
1

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

1
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);
    }
  }
0

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

0

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

Edited by Chirag_97: Spelling Mistake

0

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

Edited by AndrisP

0

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

Edited by Chirag_97: Spelling Mistake

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.