finfo_file
Description
The finfo_file of Fileinfo for PHP returns information about a file.
Syntax
finfo_file(
finfo $finfo,
string $filename,
int $flags = FILEINFO_NONE,
?resource $context = null
): string|falseParameters
finfo
An finfo instance, 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.
Return
Returns a textual description of the contents of the filename argument, or false if an error occurred.
Examples
1 · finfo filename
<?
$finfo = finfo_open();
if($finfo === false)
{
die("finfo_open");
}
$filename = $_SERVER["DOCUMENT_ROOT"]. "/assets/txt/1.txt";
$return = finfo_file($finfo, $filename);
echo $return;
finfo_close($finfo);
ASCII text, with no line terminators
2 · flags
<?
$finfo = finfo_open();
if($finfo === false)
{
die("finfo_open");
}
$filename = $_SERVER["DOCUMENT_ROOT"]. "/assets/txt/1.txt";
$flags = FILEINFO_MIME_TYPE;
$return = finfo_file($finfo, $filename, $flags);
echo $return;
finfo_close($finfo);
text/plain
3 · context
<?
$finfo = finfo_open();
if($finfo === false)
{
die("finfo_open");
}
$filename = $_SERVER["DOCUMENT_ROOT"]. "/assets/txt/1.txt";
$flags = FILEINFO_MIME_TYPE;
$context = stream_context_create();
$return = finfo_file($finfo, $filename, $flags, $context);
echo $return;
finfo_close($finfo);
text/plain