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??
How do I go up a directory in php without using /.../...
Moderator: General Moderators
-
johnny12358
- Forum Newbie
- Posts: 1
- Joined: Sun Apr 25, 2010 2:50 pm
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: How do I go up a directory in php without using /.../...
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.
(#10850)
Re: How do I go up a directory in php without using /.../...
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;
}