Class Magic

Description

This class is used to classify the given file using some magic bytes characteristic to a particular file type. The classification information can be a MIME type or just text describing the file.

This method is slower than determining the type by file suffix but on the other hand reduces the risk of fail positives during the test.

The magic file consists of ASCII characters defining the magic numbers for different file types. Each row has 4 to 5 columns, empty and commented lines (those starting with a hash character) are ignored. Columns are described below.

  • 1 -- byte number to begin checking from. ">" indicates a dependency upon the previous non-">" line
  • 2 -- type of data to match. Can be one of following - byte (single character) - short (machine-order 16-bit integer) - long (machine-order 32-bit integer) - string (arbitrary-length string) - date (long integer date (seconds since Unix epoch/1970)) - beshort (big-endian 16-bit integer) - belong (big-endian 32-bit integer) - bedate (big-endian 32-bit integer date) - leshort (little-endian 16-bit integer) - lelong (little-endian 32-bit integer) - ledate (little-endian 32-bit integer date)
  • 3 -- contents of data to match
  • 4 -- file description/MIME type if matched
  • 5 -- optional MIME encoding if matched and if above was a MIME type

Located in /Magic.php (line 79)


	
			
Method Summary
Magic __construct (string $filename)
string|false getType (string $filename, [string $default = false])
Methods
Constructor __construct (line 89)

Reads the magic information from given magic file.

  • access: public
Magic __construct (string $filename)
  • string $filename: The path to the magic file.
getType (line 107)

Returns the recognized MIME type/description of the given file. The type is determined by the content using magic bytes characteristic for the particular file type.

If the type could not be found, the function returns the default value, or false.

  • access: public
string|false getType (string $filename, [string $default = false])
  • string $filename: The file path whose type to determine.
  • string $default: The default value.

Documentation generated on Fri, 05 Sep 2008 20:18:59 +0300 by phpDocumentor 1.4.1