Search Results

  1. Return information about a string buffer You should never rely on finfo::buffer to get the MimeType of a file, you must always save the file physically or temporariliy and use finfo_open to get MimeType. I tested it with an excell file, with buffer it says octet-stream that is not valid, with finfo_open it says ms-excell as correct.

    • Parameters
    • Return Value
    • Example 1
    • Example 3
    • Example 4
    • Summary

    Below are the parameters of the finfo_buffer()function − 1. $finfo− It is the fileinfo resource returned by finfo_open(). 2. $string− It is the string buffer to be examined. 3. $options− It is the bitmask of FILEINFO constants and the default value is FILEINFO_NONE. 4. $context− It is the context resource created with stream_context_create().

    The finfo_buffer()function returns a textual information of the string argument and FALSE on failure.

    Here is the basic example of the PHP FileInfo finfo_buffer()function to get the content type of the buffer.

    Now the below code is using the options parameter of the finfo_buffer()function to get the content type of the buffer.

    In the following example, we are using the finfo_buffer()function to use the binary data and to see how we can handle it.

    The finfo_buffer()function is a built-in method in PHP which is used to deal with the file information. And we have seen four different examples to see the usage of this function to detect the MIME type of different types of data.

  2. Dec 9, 2025 · The finfo class (part of PHP’s Fileinfo extension) is the most reliable way to detect MIME types. The finfo_buffer() method analyzes binary data directly from a string (buffer), making it perfect for file_get_contents() results.

  3. Jul 7, 2020 · Is this a bug with how the finfo->buffer method works? I noticed that PHP allocates a significant amount of memory when determining mime type using finfo, and only with certain file types like csv and txt files.

  4. PHP 5 >= 5.3.0, PHP 7, PHP 8, PECL fileinfo >= 0.1.0 finfo_buffer - Return information about a string buffer Manual Code Examples

  5. www.mirrorservice.org › functionfinfo_buffer

    This function is used to get information about binary data in a string.

  6. People also ask

  7. In PHP 8.1, the following functions from finfo extension return and accept finfo class instances instead of resource objects with type file_info. finfo_buffer finfo_close finfo_file finfo_open finfo_set_flags finfo class finfo class already exists in all PHP versions (PHP >= 5.3), but prior to PHP 8.1, the procedural-style finfo_* functions returned/accepted resources instead. From PHP 8.1, it ...