PHP finfo_open() Function Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: Procedural Style:finfo_open(Flag, magic_database = null)Object-Oriented Style: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); // Return file MIME $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() ; } // Return file MIME $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 Comment More infoAdvertise with us Next Article PHP finfo_file() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function Similar Reads PHP | opendir() Function The opendir() function in PHP is an inbuilt function which is used to open a directory handle. The path of the directory to be opened is sent as a parameter to the opendir() function and it returns a directory handle resource on success, or FALSE on failure. The opendir() function is used to open up 2 min read PHP finfo_file() Function The finfo_file() function is an inbuilt function in PHP that is used for getting information about a file. Syntax: Procedural Style: public finfo_file( string $filename, int $flags = FILEINFO_NONE, ?resource $context = null ): string|false Object-Oriented Style: public finfo::file( string $filename, 2 min read PHP finfo_close() Function The finfo_close() function is an inbuilt function in PHP that is used to close the file instance that is opened by the finfo_open() function. Syntax: finfo_close($finfo):Â boolParameters: This function accepts only one parameter which is described below. $finfo: The file info resource returned by fin 2 min read PHP | zip_open() Function The zip_open() function is an inbuilt function in PHP which is used to open a zip archive for reading. The zip_open() function creates a new stream and establishes a connection between the stream and a Zip Archive. The filename is sent as a parameter to the zip_open() function and it returns a valid 2 min read PHP fscanf() Function The fscanf() function is an inbuilt function in PHP that parses the file's input according to format, i.e., it accepts the input from a file that is associated with the stream & the input will be interpreted according to the specified format. This function is similar to sscanf() function. Any wh 2 min read PHP | zip_entry_open() Function The zip_entry_open() function is an inbuilt function in PHP which is used to open a zip entry archive for reading. Opening a file or a directory in a zip archive with the zip_entry_open function creates a new stream and establishes a connection between the stream and a file or a directory in a Zip A 3 min read Like