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, laravel 8, laravel 9, laravel 10 and laravel 11.
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. 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, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Check If Request Has File in Laravel?
- How to use Carbon in Laravel Blade or Controller File?
- How to Call Controller Function in Blade Laravel?
- Laravel Redirect to Route from Controller Example
- Laravel Http Curl Delete Request Example
- Laravel Form Validation Request Class Example
- Laravel React JS Axios Post Request Example Tutorial
- How to Check Request is Ajax or Not in Laravel?
- How to Check Request Method is GET or POST in Laravel?
- How to Get Last Inserted Id in Laravel?
- Laravel Order By with Column Value Example
- How to Get Query Log in Laravel Eloquent?
- How to Set URL without Http of Other Site in Laravel?
- Laravel Create JSON File & Download From Text Example