PHP Code to Get File name of a file

Getting the name of the file, while uploading is important. Because we have to validate whether the uploading file’s name is already present, if already exists then we have to rename the currently uploading file name.

Here is the php code to get the file name using substr()  and strrpos()

1
2
3
4
5
<?php
$filename = "sample.jpg"
$name=substr($filename, 0, strrpos($filename, '.'));
echo $name;
?>

 

 

 

prasad

About prasad

Prasad K has written 111 post in this blog.