PHP检查文件存在而不知道扩展名
问题描述:
我需要检查文件是否存在,但是我不知道扩展名.
I need to check if a file exists but I don't know the extension.
我想做的IE:
if(file_exists('./uploads/filename')):
// do something
endif;
当然没有用,因为它没有扩展名.扩展名将为jpg,jpeg,png,gif
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 ?
答
您将必须执行 glob():
You would have to do a glob():
$result = glob ("./uploads/filename.*");
,然后查看$result
是否包含任何内容.
and see whether $result
contains anything.