hello,
you can use some string functions like
strpos() or strchr() which return the first and last occurence of a 'needle' within a 'haystack'.
You will get the position and based on this you can extract the string which is before the last occurence of'/'.this is the path you want.
I have not tried working this out but i think it will work.
cheers!