Check if file exists without extension

I echo’d it and got http://www.domain.co.uk/images/montage/montage-2.{jpg,png,gif,jpeg}

I see your point already. I’ve changed it to the directory rather than url and it works! thanks!

Good work. :slight_smile:

But how would I now echo it as an image to the user now? At current I have:


if(is_array($files) && count($files > 0)){
return '<img alt="Montage" src="'.$files[0].'" />';
}

Which returns image location as g:\websites\ hissite\htdocs\images\montage\montage-4.png

Shows it exists but no good for the user. Shouldn’t glob just return the filename?

No, it shouldn’t. This is because glob() can return files from multiple folders (given an appropriate pattern). You could str_replace() the filesystem path with the URL path, or use basename() with the path, it’s up to you.

basename() worked a treat, thanks. You’ve been a great help!