(PHP >= 5.3.0, PECL fileinfo >= 0.1.0)
finfo_file -- finfo::file — Return information about a file
Procedural style
$finfo
, string $filename
[, int $flags
= FILEINFO_NONE
[, resource|null $context
= NULL
]] ) : string|falseObject oriented style
$filename
[, int $flags
= FILEINFO_NONE
[, resource|null $context
= NULL
]] ) : string|falseThis function is used to get information about a file.
finfo
Fileinfo resource returned by finfo_open().
filename
Name of a file to be checked.
flags
One or disjunction of more Fileinfo constants.
context
For a description of contexts
, refer to Stream Functions.
Returns a textual description of the contents of the
filename
argument, or FALSE
if an error occurred.
Version | Description |
---|---|
8.0.0 |
context is nullable now.
|
Example #1 A finfo_file() example
<?php
$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala 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