是否有可能不知道它的文件扩展名? [英] Is it possible to get a file extension without knowing it?

查看:116
本文介绍了是否有可能不知道它的文件扩展名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为94bf663a100e848fb599209af8cdc2b5.wmv的文件。我知道 pathinfo 不会给我扩展名,如果我只使用名称94bf663a100e848fb599209af8cdc2b5。我相信 glob 仅用于检查文件是否存在。那么是否有可能得到一个文件扩展名,只知道文件名(94bf663a100e848fb599209af8cdc2b5)? 解决方案

href =http://php.net/manual/en/function.glob.php =noreferrer> php glob手册页建议, glob 不是只是检查文件是否存在,它会返回与表达式匹配的每个文件。



这里是对该页面为您的需要:

  $ name =94bf663a100e848fb599209af8cdc2b5; 
$ matching = glob($ name。。*);

$ info = pathinfo($ matching [0]);
$ ext = $ info ['extension'];

这里假设有一个(也是唯一的) / em>扩展名),但是如果该文件可能不存在,或者可能有多个具有相同名称和不同扩展名的文件,则应该可以修改它。


I have a file called 94bf663a100e848fb599209af8cdc2b5.wmv. I know pathinfo will not give me the extension if I just use the name 94bf663a100e848fb599209af8cdc2b5. I believe glob is only for checking if a file exists. So is it possible to get a file extension just knowing the file name (94bf663a100e848fb599209af8cdc2b5)?

解决方案

As the example on the php glob manual page suggests, glob does not simply check if the file exists, it returns every file that matches the expression.

Here's a modification of the example on that page for your needs:

$name = "94bf663a100e848fb599209af8cdc2b5";
$matching = glob($name . ".*");

$info = pathinfo($matching[0]);
$ext = $info['extension'];

This assumes there is one (and only one) file with that name (with any extension), but you should be able to modify it if the file might not exist, or there might be multiple files with the same name, and different extensions.

这篇关于是否有可能不知道它的文件扩展名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆