0

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 ?

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
PHP_USER1
  • 628
  • 1
  • 14
  • 29
  • use this $info = new SplFileInfo('/path/to/foo.txt'); var_dump($info->getFilename()); – Praveen D Oct 03 '13 at 06:24
  • 2
    possible 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 Answers4

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

1) link1
2) link2
3) link3
4)link4

Community
  • 1
  • 1
Kushal Suthar
  • 423
  • 6
  • 21
0
$baseName = basename($cpic);

See http://php.net/manual/function.basename.php

Phil
  • 157,677
  • 23
  • 242
  • 245
0

basename()should give you what you want.

interskh
  • 2,511
  • 4
  • 20
  • 20
-1
$cpic = substr(strrchr($pic_name, '/'), 1);

Even though Phil's answer might be easier!

Cyrille Armanger
  • 649
  • 5
  • 18