trying to ignore one file within a list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
saulstokes
Forum Newbie
Posts: 2
Joined: Sun May 17, 2009 2:54 pm

trying to ignore one file within a list

Post by saulstokes »

Hi, I'm using the php code below to list the contents of a folder. However, in that folder, I want to ignore one thing. In this case, it's the .htaccess. i don't want this to appear in this list or show up as a link. Would someone mind showing me the process for doing this? Essentially, I would like to modify the code below so that .htaccess will not show up.

Thank you,
Saul

.htaccess
accents
bassdrums
claps
crashes
hats
index.html
signnocker_bd.mp3
small pitched_bd.mp3
snares
toms


Code: Select all

 
<html>
<head><title>page</title>
</head>
<body>
<?php
$dir=opendir(".");
$files=array();
while (($file=readdir($dir)) !== false)
{
if ($file != "." and $file != ".." and $file != "index.php")
{
array_push($files, $file);
}
}
closedir($dir);
sort($files);
foreach ($files as $file)
print "<A href='$file'>$file</a>
<BR>"; 
?>
</body>
</html>
 
Last edited by Benjamin on Mon May 18, 2009 9:51 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: trying to ignore one file within a list

Post by califdon »

Please follow the rules of this forum and don't post PHP code like that without enclosing it in code tags, for readability.

Do you see how you are already excluding the "." and ".." and "index.php" file entries? Do exactly the same for ".htaccess".
saulstokes
Forum Newbie
Posts: 2
Joined: Sun May 17, 2009 2:54 pm

Re: trying to ignore one file within a list

Post by saulstokes »

Thank you and my apologies. I'm a noobie at this and don't really understand much of it.
s
Post Reply