Documentation

Filetype
in package

All kind of file type stuff, including MIME types

Tags
internal

Used to be Mime.class.php

copyright

CLOUDREXX CMS - CLOUDREXX AG

author

Reto Kohli reto.kohli@comvation.com

subpackage

core

version
3.0.0

Table of Contents

Constants

MAXIMUM_UPLOAD_FILE_SIZE  = 1048576
Size limit in bytes for files being uploaded or stored
MIMETYPE_DEFAULT  = 'application/octet-stream'
The default MIME type used if nothing is known about the data
MIMETYPE_IMAGES_WEB  = 'image/jpeg,image/gif,image/png,image/webp'
The MIME types of images known to work in web browsers
TEXT_NAME  = 'core_filetype'
Text key for the file type name

Properties

$arrExtensions2Mimetypes  : array<string|int, mixed>
Map known extensions to MIME types
$arrMimetypes2Extensions  : array<string|int, mixed>
Map MIME types to known extensions

Methods

errorHandler()  : bool
Handle any error occurring in this class.
getImageExtensions()  : mixed
Returns an array of file name extensions that are valid for images
getImageMimetypes()  : mixed
Returns an array of MIME types for accepted images
getMimetypesForExtension()  : array<string|int, mixed>
Return the MIME type for the extension provided.
getTypeMenuoptions()  : string
Returns the HTML code for the MIME type dropdown menu
init()  : bool
Initialize the arrays of extensions and mime types on request
isKnownExtension()  : bool
Returns boolean true if the string argument is a known ending, false otherwise.
matchMimetypes()  : string
Verify that the MIME type of the file matches the specified ones.

Constants

MAXIMUM_UPLOAD_FILE_SIZE

Size limit in bytes for files being uploaded or stored

public mixed MAXIMUM_UPLOAD_FILE_SIZE = 1048576

This is set to 2^20, or 1048576 -- aka one megabyte

MIMETYPE_DEFAULT

The default MIME type used if nothing is known about the data

public mixed MIMETYPE_DEFAULT = 'application/octet-stream'

MIMETYPE_IMAGES_WEB

The MIME types of images known to work in web browsers

public mixed MIMETYPE_IMAGES_WEB = 'image/jpeg,image/gif,image/png,image/webp'

TEXT_NAME

Text key for the file type name

public mixed TEXT_NAME = 'core_filetype'

Properties

$arrExtensions2Mimetypes

Map known extensions to MIME types

private static array<string|int, mixed> $arrExtensions2Mimetypes = \false
Tags
access

private

$arrMimetypes2Extensions

Map MIME types to known extensions

private static array<string|int, mixed> $arrMimetypes2Extensions = \false
Tags
access

private

Methods

errorHandler()

Handle any error occurring in this class.

public errorHandler() : bool

Tries to fix known problems with the database table. If the table exists, it is dropped. After that, the table is created anew. Finally, the mime types known are inserted.

Tags
global

mixed $objDatabase Database object

author

Reto Kohli reto.kohli@comvation.com

Return values
bool

False. Always.

getImageExtensions()

Returns an array of file name extensions that are valid for images

public static getImageExtensions() : mixed

These include jpg, jpeg, gif, and png.

getImageMimetypes()

Returns an array of MIME types for accepted images

public static getImageMimetypes() : mixed

These include those with the extensions returned by getImageExtensions()

getMimetypesForExtension()

Return the MIME type for the extension provided.

public static getMimetypesForExtension(string $strExtension) : array<string|int, mixed>

Takes a full file name, or a file extension with or without the dot as an argument, i.e. 'cloudrexx.zip', '.gif, or 'txt'. Returns the string 'application/octet-stream' for any unknown ending. Use to test exactly that.

Parameters
$strExtension : string

The file extension

Tags
static
author

Reto Kohli reto.kohli@comvation.com

Return values
array<string|int, mixed>

The corresponding MIME types

getTypeMenuoptions()

Returns the HTML code for the MIME type dropdown menu

public static getTypeMenuoptions([string $selected = '' ]) : string
Parameters
$selected : string = ''

The optional selected MIME tpye

Tags
author

Reto Kohli reto.kohli@comvation.com

Return values
string

The menu options HTML code

init()

Initialize the arrays of extensions and mime types on request

public static init() : bool

The arrays look like this: $arrExtensions2Mimetypes = array( Extension => array( 'id' => ID, 'text_id' => Text ID, 'name' => Name, 'extension' => Extension, 'mimetype' => array( MIME Type, ... more ... ), ), ... more ... );

$arrMimetypes2Extensions = array( MIME Type => array( 'id' => ID, 'text_id' => Text ID, 'name' => Name, 'mimetype' => MIME Type, 'extension' => array( Extension, ... more ... ), ), ... more ... );

Tags
author

Reto Kohli reto.kohli@comvation.com

static
Return values
bool

True on success, false otherwise

isKnownExtension()

Returns boolean true if the string argument is a known ending, false otherwise.

public static isKnownExtension(string $strExtension) : bool
Parameters
$strExtension : string

The file extension

Tags
static
author

Reto Kohli reto.kohli@comvation.com

Return values
bool

True if the extension is known, false otherwise

matchMimetypes()

Verify that the MIME type of the file matches the specified ones.

public static matchMimetypes(string $file_name, string $accepted_types) : string

$accepted_types is a comma separated list of accepted MIME types. If the $file_name does not have an extension, this method will invariably fail and return the empty string. (I would use mime_content_type(), but it seems that this function does not exist in my version of PHP?!?...?)

Parameters
$file_name : string

The name of the file

$accepted_types : string

The list of MIME types

Return values
string

The actual MIME type if it matches one of the accepted ones, the empty string otherwise


        
On this page

Search results