Excluding index.php
Posted: Thu May 03, 2007 6:17 am
JayBird | Please use
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]
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>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]