Jump to content

parse a directory


asus
 Share

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...