简体   繁体   English

PHP查找匹配文件名的文件扩展名

[英]PHP find file extension of match filename

Let say I have image.jpg on my directory. 假设我的目录上有image.jpg。

And assume that the only detail I know is that I have a filename which name = 'image' but i don't know what it's extension. 并假设我知道的唯一详细信息是我有一个文件名,名称为“ image”,但我不知道它的扩展名。

Is there a PHP function to know the extension of the file? 有PHP函数可以知道文件的扩展名吗?

您可以使用glob查找文件:

$matching = glob('/some/directory/' . $name . '.*');

http://php.net/manual/zh/function.pathinfo.php显示了您需要的所有内容,路径,文件名和扩展名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM