DEV Community

Cover image for How to get file extension from path in Laravel 9?
dev laravel
dev laravel

Posted on • Updated on

How to get file extension from path in Laravel 9?

we will write simply get pathinfo(). how to get file extension from path in laravel. extension is here the define pathinfo(). location of your image to uplaod in your laravel code.

we will use pathinfo(). and PATHINFO_EXTENSION use this extension word after get this extension confortable.

AND WE WILL use this code get extension. laravel framwork

Example – 1 how to get file extension from path in laravel?

$_GETEXTENSTION = pathinfo(storage_path('/uploads/image.png'), 

PATHINFO_EXTENSION);

dd($_GETEXTENSTION);
Enter fullscreen mode Exit fullscreen mode

Example 2:

$_PATH_INFO = pathinfo(public_path('/uploads/image.png')); 

$_EXTENSTION = $_PATH_INFO['extension'];

dd($_EXTENSTION );
Enter fullscreen mode Exit fullscreen mode

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

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

dd($_EXTENSTION);
Enter fullscreen mode Exit fullscreen mode

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

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

dd($_EXTENSTION);
Enter fullscreen mode Exit fullscreen mode

Discussion (0)