Forum Moderators: coopster

Message Too Old, No Replies

directory links

Shows web file structure

         

brancook

7:11 pm on Sep 5, 2007 (gmt 0)

10+ Year Member



I have a file upload system put together using php. I have one page set up to upload and one page set up to view what has been uploaded. On the page for viewing files that have been uploaded there are 2 links at the top: "." and "..", which are links into some of the files within' the directory. How can I filter out those 2 links so they are not visible?

Here is my code for the page:
<?php
$current_dir = '../uploads/';
$dir = opendir($current_dir);

echo '<p>Dirctory Listing:</p><ul>';
while ($file = readdir($dir)) {
echo "<a href='http://www.example.com/uploads/$file'>$file</a>"."<br /><br />";
}
echo '</ul>';
closedir($dir);
?>

[edited by: dreamcatcher at 6:31 am (utc) on Sep. 6, 2007]
[edit reason] Use example.com, thanks. [/edit]

cameraman

7:29 pm on Sep 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may smack your head on this one - it's one of those 'too simple to work' things.
while ($file = readdir($dir)) {
if(($file!= '.') && ($file!= '..'))
echo "<a href='http://www.example.com/uploads/$file'>$file</a>"."<br /><br />";

[edited by: dreamcatcher at 6:31 am (utc) on Sep. 6, 2007]
[edit reason] Use example.com, thanks. [/edit]

brancook

7:43 pm on Sep 5, 2007 (gmt 0)

10+ Year Member



Oh my gosh...

I hate it when they are that easy...(as I smack myself in the head)

In the book I was using it says "you can easily filter out those results"

thanks for you help!
Brandon