The finfo_open() function is an inbuilt function in PHP that creates a new info instance. This function is in PHP 7 and 8.
Syntax:
finfo_open(Flag, magic_database = null)
public finfo::__construct(Flag, $magic_database = null)
Parameters: This function has only two parameters.
- Flag: One or disjunction of more file constants.
- magic-database: It specifies the name of a magic database like this /path/magic. The Magic environmental variable is used, in case if not specified. If the environmental variable is not set then PHP’s bundled magic database will be used. Passing a null or an empty string will be equivalent to the default value.
Return Value: On successful, it will return finfo instance, otherwise, it will return false on failure.
Example 1: In the below example, we will use Object Oriented Style.
PHP
<?php
$finfoinstance = new finfo(FILEINFO_MIME,null);
$filename = "./text.txt" ;
echo $finfoinstance ->file( $filename );
?>
|
Output:
application/x-empty; charset=binary
Example 2: In the below example, we will use Procedural Style.
PHP
<?php
$finfoinstance = finfo_open(FILEINFO_MIME,null);
if (!( $finfoinstance )){
echo "Opening file data is failed" ;
exit () ;
}
$filename = "./text.txt" ;
echo finfo_file( $finfoinstance , $filename );
finfo_close( $finfoinstance ) ;
?>
|
Output:
application/x-empty; charset=binary
Reference: https://www.php.net/manual/en/function.finfo-open.php
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
23 Feb, 2023
Like Article
Save Article