I am working in a php language .I am getting the data from fronthand . My problem is that I am getting a image source name ./gearedup-pics/pc_52399950497a3.png like this using post method but i need the just the name of the image ie pc_52399950497a3.png . I m storing in $cpic . so how can i get only the image name ?
Asked
Active
Viewed 240 times
0
-
use this $info = new SplFileInfo('/path/to/foo.txt'); var_dump($info->getFilename()); – Praveen D Oct 03 '13 at 06:24
-
2possible duplicate of [How to get file name from full path with PHP?](http://stackoverflow.com/questions/1418193/how-to-get-file-name-from-full-path-with-php) – Joshua Dwire Sep 04 '15 at 18:09
4 Answers
1
hey plz check out this
$name = 'gearedup-pics/pc_52399950497a3.png';
$parts = pathinfo($name);
var_dump($parts);
which will get you like a array
'dirname' => string 'gallery/painting' (length=16)
'basename' => string 'some_image_name.jpg' (length=19)
'extension' => string 'jpg' (length=3)
'filename' => string 'some_image_name' (length=15)
like
echo $parth['basename'];
and other wise you this link

Community
- 1
- 1

Kushal Suthar
- 423
- 6
- 21
-1
$cpic = substr(strrchr($pic_name, '/'), 1);
Even though Phil's answer might be easier!

Cyrille Armanger
- 649
- 5
- 18