PHP finfo_close() Function
Last Updated :
22 Sep, 2023
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): bool
Parameters: This function accepts only one parameter which is described below.
- $finfo: The file info resource returned by
finfo_open()
function.
Return Values: The finfo_close() function returns true if this function successfully closes the finfo instance of the file otherwise this function will return “false”.
Program 1: The following program demonstrates the finfo_close() function. Make sure the “text.txt” file is available in the given root location.
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
Program 2: The following program demonstrates the finfo_close() function. Make sure the given “output.txt” file is available in the given location.
PHP
<?php
$fileInfo = finfo_open(FILEINFO_MIME_TYPE);
if (! $fileInfo ) {
die ( "Failed to create Fileinfo resource." );
}
$filename = "./output.txt" ;
$fileType = finfo_file( $fileInfo , $filename );
echo "File type of $filename is: $fileType\n" ;
finfo_close( $fileInfo );
?>
|
Output:
File type of ./output.txt is: text/plain
Reference: https://www.php.net/manual/en/function.finfo-close.php
Share your thoughts in the comments
Please Login to comment...