Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Abhi324's avatar

Retrieve image from Folder - without knowing extension

Hi ,

i'm storing an image in my public/image folder through the upload function .

For the upload , its easy to get the extension : ->getClientOriginalExtension()

However now i want to retrieve that file ...i know the name but i don;t know the extension (jpg , png etc...)

how can i retrieve that file ?

        $folder = base_path() . '/public/image/';
        $name ="yyy";
        
        $path = $folder.$name;
        
        // does not work as i'm calling this on a url rather than the file
        $img_type = $img_path->getClientOriginalExtension(); 
0 likes
3 replies
jlrdw's avatar

Have a list of possible extensions to Loop through and if it's one of those extensions, I think you get the idea from there.

Abhi324's avatar

Is there a better way to do it ? since i already know the name

Please or to participate in this conversation.