Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting File Name without Extension [duplicate]

Here is my the syntax to get the Uploaded Filename with extension and Getting only the Extension

$name = Input::file('photo')->getClientOriginalName();
$extension = Input::file('photo')->getClientOriginalExtension();

Here if i upload a file named file.jpg.Then i will get

$name = file.jpg
$extension = jpg

Is there any predefined way to get only the file name i.e., file without using any string replace. If not kindly suggest a way to achieve in it str replace or any other way.

like image 808
AngularAngularAngular Avatar asked Dec 02 '22 18:12

AngularAngularAngular


1 Answers

As an alternative, if you do not want string operations you can use pathinfo():

$name = 'file.jpg';
$file_name = pathinfo($name, PATHINFO_FILENAME); // file
$extension = pathinfo($name, PATHINFO_EXTENSION); // jpg
like image 194
Kevin Avatar answered Dec 06 '22 09:12

Kevin