• PHP Video Tutorials

PHP - FileInfo Functions


Advertisements

FileInfo functions module can try to guess a content type and encoding of a file by looking for certain magic byte sequences at a specific position within a file. While it's not a bulletproof approach, the heuristics used to do a very good job.

Before PHP 5.3.0 version, the magic_open library can be needed to build this extension.

This extension can be enabled by default as of PHP 5.3.0. Before this time, fileinfo was a PECL extension but no longer maintained there.

Windows users must include bundled php_fileinfo.dll DLL file in php.ini to enable this extension.

The libmagic library can be bundled with PHP but include PHP specific changes. A patch against libmagic named libmagic.patch is maintained and may be found within a PHP fileinfo extensions source.

Predefined Constants

The constants are defined below by this extension and can be available only when an extension has either compiled into PHP or dynamically loaded at runtime.

  • FILEINFO_NONE (integer) − No special handling.

  • FILEINFO_SYMLINK (integer) − Follow symlinks.

  • FILEINFO_MIME_TYPE (integer) − Return the mime type. Available since PHP 5.3.0.

  • FILEINFO_MIME_ENCODING (integer) − Return the mime encoding of the file. Available since PHP 5.3.0.

  • FILEINFO_MIME (integer) − Return the mime type and mime encoding as defined by RFC 2045.

  • FILEINFO_COMPRESS (integer) − Decompress compressed files. Disabled since PHP 5.3.0 due to thread safety issues.

  • FILEINFO_DEVICES (integer) − Look at the contents of blocks or character special devices.

  • FILEINFO_CONTINUE (integer) − Return all matches, not just the first.

  • FILEINFO_PRESERVE_ATIME (integer) − If possible preserve the original access time.

  • FILEINFO_RAW (integer) − Don't translate unprintable characters to a \ooo octal representation.

  • FILEINFO_EXTENSION (integer) − Returns the file extension appropiate for a the MIME type detected in the file. For types that commonly have multiple file extensions, such as JPEG images, then the return value is multiple extensions speparated by a forward slash e.g.: "jpeg/jpg/jpe/jfif". For unknown types not available in the magic.mime database, then return value is "???". Available since PHP 7.2.0.

Sr.No Function & Description
1

finfo_buffer()

This Function can return information about a string buffer.

2

finfo_close()

This Function can close a fileinfo resource.

3

finfo_file()

This Function can return information about a file.

4

dio_open()

This Function can create a new fileinfo resource.

5

finfo_set_flags()

This Function can set libmagic configuration option.

6

mime_content_type()

This Function can detect MIME Content-type for a file (deprecated).

7

finfo_class()

This Function can set terminal attributes and baud rate for a serial port.

8

finfo::_construct()

This Function is an alias of finfo_open().

php_function_reference.htm

Useful Video Courses


Video

PHP Online Training

45 Lectures 9 hours

Malhar Lathkar

Video

Become PHP Facebook Developer: Password-Less Authentication

34 Lectures 4 hours

Syed Raza

Video

Ultimate PHP & MySQL Web Development Course & OOP Coding

84 Lectures 5.5 hours

Frahaan Hussain

Video

Learn PHP from Scratch

17 Lectures 1 hours

Nivedita Jain

Video

E Commerce Website Development In PHP With PDO

100 Lectures 34 hours

Azaz Patel

Video

PHP in Telugu

43 Lectures 5.5 hours

Vijay Kumar Parvatha Reddy

Advertisements