Page 1 of 1

How do I go up a directory in php without using /.../...

Posted: Sun Apr 25, 2010 2:58 pm
by johnny12358
Hi, I am making a file browser in PHP, and I am struggling to go up a directory without using the /.../.

I don't like it because it makes all the file locations very long, and its just so annoying.

Can anybody please help??

Re: How do I go up a directory in php without using /.../...

Posted: Sun Apr 25, 2010 3:10 pm
by Christopher
Instead of $path . "/../" do dirname($path) . "/". Each time you call dirname() it will remove the last thing in the path -- either a file or dir name.

Re: How do I go up a directory in php without using /.../...

Posted: Sun Apr 25, 2010 3:12 pm
by requinix
Use /../, but if you find that, don't actually stick it into the path. Use dirname instead.

Code: Select all

if ($go_into == "..") {
    $path = dirname($path);
} else if ($go_into != ".") {
    $path = $path . "/" . $go_into;
}