Page 1 of 1

Excluding index.php

Posted: Thu May 03, 2007 6:17 am
by gcclinux
JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello everyone,

I have a bit of code that list all files and directories in the current directory and it does almost exactly what I want apart from the fact that I would like to exclude the index.php file it self from being listed.

This is the current code i've written. (with help)

Code: Select all

<?php
echo '<h1><center> "Personal Photo Directory" </h1>';

function dir_to_array ($dir, $pattern = '.*' )
{
  $contents = array();
  if ($dh = opendir($dir))
  {
    while (($file = readdir($dh)) !== false)
    {
      if ( preg_match('/'.$pattern.'/',$file)&& $file!="." && $file !=".." )
          $contents[] = $file;
    }
    closedir($dh);
  }

  sort($contents);
  return $contents;
}

# Get the list of files
$dir_list = dir_to_array('./','.*.*');

# Print them out
foreach ($dir_list as $filename)
  echo '<br><center> <a href="./'.$filename.'">'.$filename.'</a>';
?>
<br><br>
<a>----------------------------------------</a><br><br>
As you can see it does what it is suppose to do, so now all i need is to excluded it self, any help will be greatly appreciated.

Many Thanks

Ricardo


JayBird | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Thu May 03, 2007 7:03 am
by feyd
Do you not know where to add the logic to exclude values?

Posted: Thu May 03, 2007 7:29 am
by gcclinux
JayBird I do apologies for the inconvenience that I have caused, I will remember to post it correctly in the future.
feyd I have tried a number of things but I do not seem to get it to work, I would appreciate your help, or anyone that knows.
Many Thanks

Ricardo

Posted: Thu May 03, 2007 7:45 am
by shiznatix

Code: Select all

if ( preg_match('/'.$pattern.'/',$file)&& $file!="." && $file !=".." && $file != "index.php")

Posted: Thu May 03, 2007 7:57 am
by gcclinux
shiznatix wrote:

Code: Select all

if ( preg_match('/'.$pattern.'/',$file)&& $file!="." && $file !=".." && $file != "index.php")
Thank you so much. I should have paid more attention and I would have figured it out!

Once again thank you.

Ricardo

Posted: Thu May 03, 2007 8:05 am
by shiznatix
gcclinux wrote:Thank you so much. I should have paid more attention and I would have figured it out!

Once again thank you.

Ricardo
don't worry baby, I'm here for you. Just keep typing to me so softly.

Posted: Thu May 03, 2007 8:20 am
by d3ad1ysp0rk
shiznatix wrote:
gcclinux wrote:Thank you so much. I should have paid more attention and I would have figured it out!

Once again thank you.

Ricardo
don't worry baby, I'm here for you. Just keep typing to me so softly.
Uhhh.. sketchy talk with long time forum members = weird, but okay.

Sketchy talk with new forum members = NO! Bad shiznatix! :lol: