finfo_file
finfo::file
(PHP >= 5.3.0, PHP 7, PHP 8, PECL fileinfo >= 0.1.0)
finfo_file -- finfo::file — Return information about a file
Description
Procedural style
Object-oriented style
This function is used to get information about a file.
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.
Examples
Example #1 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