I have been trying to get the extension from an uploaded file, searching on google, I got no results.
The file already exists in a path:
\Storage::get('/uploads/categories/featured_image.jpg);
Now, How can I get the extension of this file above?
Using input fields I can get the extension like this:
Input::file('thumb')->getClientOriginalExtension();
Thanks.
There are a few different ways to extract the extension from a filename with PHP, which is given below: Using pathinfo() function: This function returns information about a file. If the second optional parameter is omitted, an associative array containing dirname, basename, extension, and the filename will be returned.
Below the Laravel approach for moving after upload. From the documentation: $request->file('photo')->move($destinationPath); $request->file('photo')->move($destinationPath, $fileName); photo is the name of your file upload input element.
Tested in laravel 5.5
$extension = $request->file('file')->extension();
The Laravel way
Try this:
$foo = \File::extension($filename);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With