Horje
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): 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();
}
  
// Return file MIME
$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
  
// Create a new Fileinfo resource
$fileInfo = finfo_open(FILEINFO_MIME_TYPE);
  
// Check if the Fileinfo resource
// was created successfully
if (!$fileInfo) {
    die("Failed to create Fileinfo resource.");
}
  
// Get the file type of a specific file
$filename = "./output.txt";
$fileType = finfo_file($fileInfo, $filename);
echo "File type of $filename is: $fileType\n";
  
// Close the Fileinfo resource
finfo_close($fileInfo);
  
?>

Output:

File type of ./output.txt is: text/plain

Reference: https://www.php.net/manual/en/function.finfo-close.php




Reffered: https://www.geeksforgeeks.org


PHP

Related
PHP finfo_set_flags() Function PHP finfo_set_flags() Function
PHP ob_get_contents() Function PHP ob_get_contents() Function
PHP SplFileObject fpassthru() Function PHP SplFileObject fpassthru() Function
PHP SplFileObject fseek() Function PHP SplFileObject fseek() Function
PHP stripcslashes() Function PHP stripcslashes() Function

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
14