PHP get image file path?

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/ 
+6
source share
2 answers

To get the parent folder of a file:

 dirname("localhost/example/folder/filename.jpg"); 

See: document

+6
source

Use dirname()

 <?php echo dirname('localhost/example/folder/filename.jpg'); ?> 
+7
source

Source: https://habr.com/ru/post/944318/


All Articles