finfo_file

finfo::file

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

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

說明

過程化風格

finfo_file(
    resource $finfo,
    string $file_name = null,
    int $options = FILEINFO_NONE,
    resource $context = null
): string

面向對象風格

public finfo::file(string $file_name = null, int $options = FILEINFO_NONE, resource $context = null): string

本函數用來獲取一個文件的信息。

參數

finfo

finfo_open() 函數所返回的 fileinfo 資源。

file_name

要檢查的文件名。

options

一個 Fileinfo 常量 或多個 Fileinfo 常量 進行邏輯或運算。

context

關于 contexts 的更多描述,請參考 Stream 函數。

返回值

返回 file_name 參數指定的文件信息。 發(fā)生錯誤時返回 false

范例

示例 #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

參見