简体   繁体   中英

PHP find file extension of match filename

Let say I have image.jpg on my directory.

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.

Is there a PHP function to know the extension of the file?

您可以使用glob查找文件:

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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