Get file name without extension

Here is my syntax for getting the loaded filename with extension and getting only extension

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

Here, if I upload a file with a name file.jpg. Then i will get

$name = file.jpg
$extension = jpg

Is there any predefined way to get just the file name, i.e. filewithout replacing any string. If you are not kind enough to offer a way to achieve str, replace it in some other way.

+4
source share
1 answer

Alternatively, if you do not want to perform string operations, you can use pathinfo():

$name = 'file.jpg';
$file_name = pathinfo($name, PATHINFO_FILENAME); // file
$extension = pathinfo($name, PATHINFO_EXTENSION); // jpg
+13
source

All Articles