Jump to content


Photo

displaying directory


  • Please log in to reply
1 reply to this topic

#1 Maverickb7

Maverickb7
  • Members
  • PipPipPip
  • Advanced Member
  • 112 posts

Posted 11 October 2006 - 02:03 AM

hello, I was wondering if someone could put me in the direction of some code that would take all files within a certain directory and put it into an array. Does anyone know where I can find this.. I'm trying to find some good examples.

#2 shiny_spoon

shiny_spoon
  • Members
  • PipPip
  • Member
  • 26 posts
  • LocationCanada

Posted 11 October 2006 - 03:39 AM

I'm going to assume you meant file names and not data. ;)

<?php
  $i = 0;
  $path = 'my_directory';
  $dir=opendir($path);
  while ($file=readdir($dir))
  {
      if ($file != "." && $file != ".." && is_file($file) )
      {
         $my_file_array[$i] = $file;
         $i++;
      }
  }
?>

I'm also going to assume you wanted only files in there and not folders. If this is incorrect, simply remove
&& is_file($file)
from the
if
statement!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users