PHP检查文件存在而不知道扩展名 [英] PHP check file exists without knowing the extension
本文介绍了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.
这篇关于PHP检查文件存在而不知道扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文