Tuesday, January 29, 2013

Display All files and Contents in a Directory.

Display all files name with content.

(Using RecursiveDirectoryIterator PHP >=5.1.2)

-is_file check the each object values in directory list. suppose file name is occurred display the filename and content.
-highlight_file() display the file content.

<?php

 $path = "C:/xampp/htdocs/samplejoomla/application/controllers/administrator/";

      $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path),  RecursiveIteratorIterator::SELF_FIRST);

      foreach($objects as $name => $object){
          echo '<b>'.$name."</b> \n <br/>";
          if(is_file($name))
          {
            echo highlight_file($name);
           
          }
           echo "<br/><br/><br/>";

          }

?>

How to display the file and directory list.

This code run php versions >= 5.1.2

This code is very useful and simple display the particular path directory and file list.

<?php

$path = "C:/xampp/htdocs/samplejoomla/application/controllers/administrator/";


$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);

foreach($objects as $name => $object){
   echo "$name\n"."<br/>";
  }


?>