finfo_file
(PHP >= 5.3.0, PHP 7, PHP 8, PECL fileinfo >= 0.1.0)
Return information about a file
Description
Procedural
Oop
This function is used to get information about a file.
Parameters
finfoFinfo
filenameName of a file to be checked.
flagsOne or disjunction of more Fileinfo constants.
contextFor a description of
contexts, refer to ref.stream.
Return Values
Returns a textual description of the contents of the filename argument, or false if an error occurred.
Errors/Exceptions
Throws a ValueError if filename contains any null bytes. Prior to PHP 8.5.0, a TypeError was thrown instead.
Changelog
| Version | Description |
|---|---|
| 8.5.0 | A ValueError is now thrown instead of a TypeError when filename contains null bytes. |
| 8.0.0 | context is nullable now. |
Examples
A finfo_file() example
<?php
$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type aka mimetype extension
foreach (glob("*") as $filename) {
echo finfo_file($finfo, $filename) . "\n";
}
finfo_close($finfo);
?>The above example will output something similar to:
text/html
image/gif
application/vnd.ms-excel