Page 1 of 1

[SOLVED] Directory listing

Posted: Mon Nov 10, 2003 9:03 am
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?

Posted: Mon Nov 10, 2003 9:18 am
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

Posted: Mon Nov 10, 2003 9:19 am
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? :/

Posted: Mon Nov 10, 2003 9:21 am
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

Posted: Mon Nov 10, 2003 9:23 am
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

Posted: Mon Nov 10, 2003 9:26 am
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

Posted: Mon Nov 10, 2003 9:27 am
by vigge89
oops :(

Sorry :oops: