How to get file extension from path in Laravel?

About Us:

We are from free coder. We are a group of web developers who are passionate about web development. You can learn from us php, laravel, node js, vue js, react js and many other topic on web developement.
we are very happy to help you.
free coder

Today what you are going to learn:

You can simply use pathinfo() for get file extension from string in php laravel. we might some time require to get file extension from location of file or image in laravel 6, laravel 7 and laravel 8.

Here will show you simply way to get file extension from storage path or public path. we will use pathinfo() of code php.

we will use pathinfo() with PATHINFO_EXTENSION parameter to getting image extension in php laravel framework.

Lesson 1:

$extension = pathinfo(storage_path('/uploads/my_image.jpg'), PATHINFO_EXTENSION);

dd($extension);

Lesson 2:

$infoPath = pathinfo(public_path('/uploads/my_image.jpg'));

$extension = $infoPath['extension'];

dd($extension);

If you have file object from request then you can simply get by laravel function.

$extension = $request->file->extension();

dd($extension);

If you have file object from request then you can simply get by laravel function.

$extension = $request->file->getClientOriginalExtension();

dd($extension);

thank you very much for following up with me.

Recent Posts

Related Posts