[SOLVED] Directory listing

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
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

[SOLVED] Directory listing

Post by vigge89 »

ive made a PHP page which lists all the file in the selected folder, code for it is:

Code: Select all

<?php
$dir_handle = @opendir($path) or die("Can't open directory "$path".");

while (false !== ($file = readdir($dir_handle))) {

echo "<a href="/uploaded/$file">$file</a><br>";

}

closedir($dir_handle);
?>
But when i run it, before printing the uploaded files, it prints:

Code: Select all

&lt;a href="/uploaded/."&gt;.&lt;/a&gt;&lt;br&gt;&lt;a href="/uploaded/.."&gt;..&lt;/a&gt;&lt;br&gt;
, or hyperlinked dots (. \n ..)

how come it does that?
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

.. returns you to the parent directory

. is the current directory

Like in DOS when you type cd.. to go up one directory level.

Mark
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Bech100 wrote:.. returns you to the parent directory

. is the current directory

Like in DOS when you type cd.. to go up one directory level.

Mark
ok, how should I do if I don't want e'm then? :/
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

The manual is a great place to find out stuff like this, always check it out first. Anyway try this from the manual

Code: Select all

<?php 
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) { 
        if ($file != "." && $file != "..") { 
            echo "$file\n"; 
        } 
    }
    closedir($handle); 
}
?>
Mark
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Bech100 wrote:The manual is a great place to find out stuff like this, always check it out first. Anyway try this from the manual

Code: Select all

<?php 
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) { 
        if ($file != "." && $file != "..") { 
            echo "$file\n"; 
        } 
    }
    closedir($handle); 
}
?>
Mark
thanks :D
Last edited by vigge89 on Mon Nov 10, 2003 10:24 am, edited 1 time in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

vigge89 wrote:yep, but as I was sure that someone would help me faster than I browsed to the manual and went trought it, I waited some mins :D

thanks :D
That is not a good attitude - why should others do your work for you? Next time try the manual first.

Mac
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

oops :(

Sorry :oops:
Post Reply