Jump to content

Archived

This topic is now archived and is closed to further replies.

Maverickb7

displaying directory

Recommended Posts

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.

Share this post


Link to post
Share on other sites
I'm going to assume you meant file names and not data. ;)

[code]
<?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++;
      }
  }
?>
[/code]

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.