List only some extention (File Listing)

Discussion in 'Programming' started by Peuplarchie, Nov 9, 2008.

  1. #1
    Good day to you all,
    I'm working on a pice of code which list all files in a directory and return the list and its content right under the name of the file.

    
    
    <?php
    $thelist = "";
     if ($handle = opendir('.')) {
       while (false !== ($file = readdir($handle)))
          {
              if ($file != "." && $file != "..")
    	  {
              	$thelist .= '<a href="'.$file.'">'.$file.'</a><br/>';
                $contents = file($file);
                $string = implode($contents);
                $thelist .= '<p>'.$string.'</p>';
                
              }
           }
      closedir($handle);
      }
    ?>
    <P>List of files:</p>
    <P><?=$thelist?></p>
    
    
    PHP:

    I'm looking for a way of choose only 3 or 4 extension only.

    How would I dow so ?

    Thanks !
     
    Peuplarchie, Nov 9, 2008 IP
  2. happpy

    happpy Well-Known Member

    Messages:
    926
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    120
    #2
    hi

    where it says
              if ($file != "." && $file != "..")
    Code (markup):
    replace with
              if (eregi("txt$",$file) || eregi("jpg$",$file) || eregi("gif$",$file))
    Code (markup):
    replace extension how you need, add more if needed.

    enjoy
     
    happpy, Nov 10, 2008 IP