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
liquid
Forum Newbie
Posts: 14 Joined: Thu Oct 21, 2004 2:19 pm
Location: Wyoming USA
Post
by liquid » Thu Nov 11, 2004 4:14 pm
Im trying to display a dir's contents. Which is working fine except that it is also displaying the dir structure:
example:
. <--- do not want this to display
.. <--- do not want this to display
first file
second file
etc...
How do I get rid of those first entries????
Code: Select all
<?php
$dir = "fileupload/uploads/".$row['cname']."/";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
do{
echo "<a href="$dir$file" target="_blank">";
echo $file;
echo "</a>";
echo "<br>";
}while(($file = readdir($dh)) !== false);
closedir($dh);
}
}
?>
Thanks in advance!
liquid
timvw
DevNet Master
Posts: 4897 Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium
Post
by timvw » Thu Nov 11, 2004 4:17 pm
just make sure the file does not equal '.' or '..'
rehfeld
Forum Regular
Posts: 741 Joined: Mon Oct 18, 2004 8:14 pm
Post
by rehfeld » Thu Nov 11, 2004 4:24 pm
Code: Select all
<?php
if ($handle = opendir($dir)) {
while (false !== ($filename = readdir($handle))) {
if ($filename !== '.' && $filename !== '..') {
echo $filename;
}
}
closedir($handle);
}
?>
liquid
Forum Newbie
Posts: 14 Joined: Thu Oct 21, 2004 2:19 pm
Location: Wyoming USA
Post
by liquid » Thu Nov 11, 2004 4:31 pm
OMG...duh.. I cant believe I didnt think of that! Time to go home.
Thanks much for the quick reply!!