How to get file extension from path in Laravel?

How to get file extension from path in Laravel?


tutorials - 5 undefined, 2020

How to get file extension from path in Laravel?

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.

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.

Example 1:

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

dd($extension);

Example 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->getClientOriginalExtension();

dd($extension);

I hope it can help you...

Our Sponsors

NodeJS Experts
React Experts
PHP Experts
AngularJS Experts
Aws Experts
Firebase Experts

Top Applications in TutorialStuff

Top Experts In TutorialStuff

Trending On TutorialStuff