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
vigge89
Forum Regular
Posts: 875 Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden
Post
by vigge89 » Mon Nov 10, 2003 9:03 am
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
<a href="/uploaded/.">.</a><br><a href="/uploaded/..">..</a><br>
, or hyperlinked dots (. \n ..)
how come it does that?
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Nov 10, 2003 9:18 am
.. returns you to the parent directory
. is the current directory
Like in DOS when you type cd.. to go up one directory level.
Mark
vigge89
Forum Regular
Posts: 875 Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden
Post
by vigge89 » Mon Nov 10, 2003 9:19 am
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? :/
JayBird
Admin
Posts: 4524 Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:
Post
by JayBird » Mon Nov 10, 2003 9:21 am
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
vigge89
Forum Regular
Posts: 875 Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden
Post
by vigge89 » Mon Nov 10, 2003 9:23 am
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
Last edited by
vigge89 on Mon Nov 10, 2003 10:24 am, edited 1 time in total.
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Mon Nov 10, 2003 9:26 am
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
thanks
That is not a good attitude - why should others do your work for you? Next time try the manual first.
Mac
vigge89
Forum Regular
Posts: 875 Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden
Post
by vigge89 » Mon Nov 10, 2003 9:27 am
oops
Sorry