finfo_file

finfo::file

(PHP >= 5.3.0, PHP 7, PHP 8, PECL fileinfo >= 0.1.0)

finfo_file -- finfo::file返回一个文件的信息

说明

过程化风格

finfo_file(
    finfo $finfo,
    string $filename,
    int $flags = FILEINFO_NONE,
    ?resource $context = null
): string|false

面向对象风格

public finfo::file(string $filename, int $flags = FILEINFO_NONE, ?resource $context = null): string|false

本函数用来获取一个文件的信息。

参数

finfo

finfo_open() 返回的 finfo 实例。

filename

要检查的文件名。

flags

一个 Fileinfo 常量或多个进行逻辑或。

context

关于 contexts 的更多描述,请参考 Stream 函数

返回值

返回 filename 参数指定的文件信息。发生错误时返回 false

更新日志

版本 说明
8.1.0 finfo 参数现在接受 finfo 实例,之前接受 资源(resource)
8.0.0 context 现在可以为 null。

范例

示例 #1 finfo_file() 示例

<?php
$finfo
= finfo_open(FILEINFO_MIME_TYPE); // 返回 mime 类型
foreach (glob("*") as $filename) {
echo
finfo_file($finfo, $filename) . "\n";
}
finfo_close($finfo);
?>

以上例程的输出类似于:

text/html
image/gif
application/vnd.ms-excel

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top