Arbit - project tracking

Arbit - project tracking

API documentation :: Docs For Class arbitFrameworkMimeTypeGuesser

Core::arbitFrameworkMimeTypeGuesser

Class arbitFrameworkMimeTypeGuesser

This class provides the basics for file mime type guessing and validation.

This class provides the basics for file mime type guessing and validation. The mime types are basically guessed on the base of the file extension, which is rather inaccurate, because it is purely user provided value. For certain file types we offer callbacks, which may perform an additional validation step to ensure the file is of the guessed type, like for images, where we may use the PHP function getimagesize(), or to ensure proper contents in text files.

Author(s):
Version:   $Revision: 1236 $
License:   GPL

Member Variables

protected static array $extensionMapping
Mapping of file extensions to mime types.

Mapping of file extensions to mime types. A list may be found at, and can be extended further from: http://www.w3schools.com/media/media_mimeref.asp

protected static array $validationCallbackMap
Additional validation mechanisms for mime types matching the given regular expressions.

Additional validation mechanisms for mime types matching the given regular expressions. The key of this array is a PCRE regular expression, which defines the mime types for which the given callback should be called to verify the guessed mime type. The callback method may modifiy the mimetype, in case of a validation error this should be modified to 'application/octet-stream'. You may add general validation mechanisms here, which may add a general intrusion scan or use some common mime type detection mechanism.

Method Summary

protected static string checkImageMimeType( $file , $mimeType )
Check and validate guessed image mime type Tries to verify the guessed mime typ of image files using PHPs function getimagesize. detected the method will always fall back to 'application/octet-stream'.
protected static string checkText( $file , $mimeType )
Check text contents.
public static string guess( $file , [ $userMimeType = false] )
Guess mime type Guess the mime type of the given file, basically based on the file extension and optional additional validation mechanisms. mime type may be completely wrong, and just is a fair guess. really rely on user provided data.

Methods

checkImageMimeType

static string checkImageMimeType( string $file , string $mimeType )

Check and validate guessed image mime type Tries to verify the guessed mime typ of image files using PHPs function getimagesize. detected the method will always fall back to 'application/octet-stream'.

Check and validate guessed image mime type Tries to verify the guessed mime typ of image files using PHPs function getimagesize. If the mimetypes do not match, or active contents are detected the method will always fall back to 'application/octet-stream'.

Parameters:
Name Type Description
$file string
$mimeType string

checkText

static string checkText( string $file , string $mimeType )

Check text contents.

Check text contents. There are some non-printable characters we do not want in text files. If we detect them in a text file, we fall back to 'application/octet-stream'.

Parameters:
Name Type Description
$file string
$mimeType string

guess

static string guess( string $file , [string $userMimeType = false] )

Guess mime type Guess the mime type of the given file, basically based on the file extension and optional additional validation mechanisms. mime type may be completely wrong, and just is a fair guess. really rely on user provided data.

Guess mime type Guess the mime type of the given file, basically based on the file extension and optional additional validation mechanisms. The returned mime type may be completely wrong, and just is a fair guess. Do never really rely on user provided data. If the user also provided a mime type, it is checked if the user provided information is consitent with the guessed type. Otherwise we fall back to the default mimetype value: 'application/octet-stream'.

Parameters:
Name Type Description
$file string
$userMimeType string
Documentation generated on Mon, 05 Apr 2010 14:02:04 +0200 by phpDocumentor 1.4.3