I need to check if a file exists but I don't know the extension.
IE I would like to do:
if(file_exists('./uploads/filename')):
// do something
endif;
Of course that wont work as it has no extension. the extension will be either jpg, jpeg, png, gif
Any ideas of a way of doing this without doing a loop ?
You would have to do a
glob():
and see whether
$result
contains anything.Did you know about the PHP filetype function? http://php.net/manual/en/function.filetype.php
Or otherwise
is_file()
http://www.php.net/manual/en/function.is-file.phpI've got the same need, and tried to use glob but this function seems to not be portable :
See notes from http://php.net/manual/en/function.glob.php :
It also more slower than opendir, take a look at : Which is faster: glob() or opendir()
So I've made a snippet function that does the same thing :
Usage :
Hope that could helps someone, Ioan