Example:
Image URL:
localhost/example/folder/filename.jpg
I want to get the path to the image so that it is:
localhost/example/folder/
How to do it?
My English is poor. Thanks!
I found a solution instead of using dirname:
$image = 'localhost/example/folder/filename.jpg'; $directory = substr($image, 0, strrpos($image, '/', -2) + 1 ); echo $directory; //return: localhost/example/folder/
source share