user3282988
user3282988

Reputation: 129

Return one folder backwards

I have a dynamic URL, for example:

"up/some_images/profile_image_15/200.png"

Is there a command that can give me the path:

"up/some_images/"

?

Upvotes: 1

Views: 84

Answers (2)

Nagaraj S
Nagaraj S

Reputation: 13484

Try this dirname — Returns parent directory's path

<?php
print_r(pathinfo(pathinfo("up/some_images/profile_image_15/200.png")["dirname"])["dirname"]);

Upvotes: 1

Halcyon
Halcyon

Reputation: 57693

Yes, use dirname()

$path = "up/some_images/profile_image_15/200.png"
$grandparentdir = dirname(dirname($path)); // "up/some_images"

If you want the trailing / you will have to add it yourself.

Upvotes: 3

Related Questions