file directory

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
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

file directory

Post by ekosoftco »

Code: Select all

<?php
$dir=dir("./$folder/.");
while($filename=$dir->read()) {
$lineArray = explode('$filename', $filename);
$ska = trim($lineArray[0]);
echo "<a href=$ska>";
$skaa = str_replace('.php', '</a><br><img src="../images/line.png" width="141" height="20" /><br>', $ska);
echo "<center>$skaa";
echo "</center>";
}
$dir->close();
?>
now this shows up correctly, i have everything right,except it shows up the root link too, the "." and ".."
so the result is
.
..
file1
file2
file3

but i dont want the "." and ".." there, is there a way to take out just that.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Add logic (checks) that exclude those two.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

So you are asking if there is a way that if $ska is equal to '.' or $ska id equal to '..' if you can not show it? Yup, it can be done. ;)
ekosoftco
Forum Contributor
Posts: 108
Joined: Fri Aug 04, 2006 8:21 pm

Post by ekosoftco »

i guess this will work :/

Code: Select all

<?php
		$dir=dir("./$folder/.");
		while($filename=$dir->read()) {
		$lineArray = explode('$filename', $filename);
		$ska = trim($lineArray[0]);
		echo "<a href=$ska>";
		$skaa = str_replace('.php', '</a><br><img src="../images/line.png" width="141" height="20" /><br>', $ska);
		$skdone = str_replace('..', ' ', $skaa);
		echo "<center>$skdone";
		echo "</center>";
		}
		$dir->close();
		?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

I was thinking more along the lines of:

Code: Select all

<?php
if ($ska != '.' && $ska != '..') {
    // ...
}
?>
Post Reply