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 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.
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->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...

My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
- Laravel 5.7 - Create REST API with authentication using Passport Tutorial
- Laravel 5.7 - Pagination Link Customizations Example
- Laravel 5.7 CRUD (Create Read Update Delete) Tutorial Example
- How to get last inserted id in Laravel?
- Order by using multiple columns and manually array field in Laravel?
- How to get last executed mysql query in Laravel?
- How to set URL without http of Other site in Laravel?
- How to create a text file for JSON and file download in Laravel?