Directory Listing in PHP

<?php
 function list_files($directory)
 {
       if(is_dir($directory)) // check it is directory or not
       {
         if($status= opendir($directory)) // asign the opendir status in $handle
         {
             while(($file = readdir($status)) !== false)
             {
                  if($file != "." && $file != ".." && $file != "Thumbs.db"/*pesky windows, images..*/)
                  {
                        echo '<a href="'.$dir.$file.'" target="_blank">'.$file.'</a>'."\n";
                  }
             }
             closedir($status);
         }
       }
  }

 list_files("images/"); //calling function
 ?>
Advertisements

One thought on “Directory Listing in PHP

Leave your comments

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s