PHP finfo_set_flags() Function Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report The finfo_set_flags() function is an inbuilt function in PHP that is used to set or change the behavior of the Fileinfo extension. It allows you to modify the flags that control the file information returned by the Fileinfo functions. Syntax: finfo_set_flags(finfo $finfo, int $flags): boolParameters: This function accepts two parameters that are described below. $finfo: A fileinfo resource obtained from finfo_open() function.$flags: An integer representing the flags to be set. These flags are constants provided by PHP.Return Values: The finfo_set_flags() function returns "true" if it successfully sets the flags otherwise this function returns "false". Program 1: The following program demonstrates the finfo_set_flags() function. PHP <?php // Create a new Fileinfo resource $fileInfo = finfo_open(FILEINFO_MIME_TYPE); // Set the flags to include MIME encoding // information finfo_set_flags($fileInfo, FILEINFO_MIME_TYPE | FILEINFO_MIME_ENCODING); // 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; charset=us-asciiProgram 2: The following program demonstrates the finfo_file() function. PHP <?php // Create a new Fileinfo resource to get MIME type $fileInfo = finfo_open(FILEINFO_MIME_TYPE); // Check if the Fileinfo resource was // created successfully if (!$fileInfo) { die("Failed to create Fileinfo resource."); } // List of filenames to check $filenames = ["example.php", "output.jpg"]; foreach ($filenames as $filename) { // Get the file type (MIME) of the current file $fileType = finfo_file($fileInfo, $filename); echo "File type of $filename is: $fileType\n"; } // Close the Fileinfo resource finfo_close($fileInfo); ?> Output: File type of example.php is: text/x-phpFile type of output.jpg is: image/jpegReference: https://www.php.net/manual/en/function.finfo-set-flags.php Comment More infoAdvertise with us Next Article PHP finfo_buffer() Function N neeraj3304 Follow Improve Article Tags : PHP PHP-function PHP-Fileinfo Similar Reads 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_open() Function 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 t 1 min read PHP | fgets( ) Function The fgets() function in PHP is an inbuilt function which is used to return a line from an open file. It is used to return a line from a file pointer and it stops returning at a specified length, on end of file(EOF) or on a new line, whichever comes first. The file to be read and the number of bytes 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 finfo_buffer() Function The finfo_buffer() is an inbuilt function in PHP that returns information about a string buffer. Syntax: Procedural Style: string | false finfo_uffer( string $string, int $flags = FILEINFO_NONE, ?resource $context = null )Object-Oriented Style: public finfo::buffer( string $string, int $flags = FILE 1 min read PHP | fileperms( ) Function The fileperms() function in PHP is an inbuilt function which is used to return the permissions given to a file or a directory. The filename of the file whose permissions have to be checked is sent as a parameter to the function and it returns the permissions given to the file in the form of numbers 2 min read Like