Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP get file path of an image?

Tags:

php

Example:

The image url:

localhost/example/folder/filename.jpg

I want to get path of the image so it must be:

localhost/example/folder/

How to do that?

I speak English not well. Thanks!

I have 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/
like image 879
Thanh Nguyen Avatar asked May 05 '13 15:05

Thanh Nguyen


1 Answers

Use dirname()

<?php
echo dirname('localhost/example/folder/filename.jpg');
?>
like image 123
Tamil Selvan C Avatar answered Oct 16 '22 02:10

Tamil Selvan C