Jump to content

parse a directory


asus

Recommended Posts

Is there a way to use html or php to parse the content of a directory on a webserver, then setup a link to those files and display them on a page? Thanks

Share this post


Link to post
Share on other sites

PHP5 has scandir() http://uk.php.net/scandir

 

I dont have 5, so I've used the following in PHP4

 

function scandir($dir)
{
  $i = 0;
  $dh = opendir($dir);

  if (!$dh) {
  return NULL;
  }

  while (false !== ($filename = readdir($dh))) {
  if ($filename == "." || $filename == "..") continue;
  $files[$i++] = $filename;
  }
  closedir($dh);

  return $files;
}

 

Which I also found on the php site (probably under scandir() comments even) and altered slightly.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...