CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 5.2 Chiffon API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 5.2
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • Cache
    • Collection
    • Command
    • Console
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
      • Client
      • Cookie
      • Exception
      • Middleware
      • Session
      • TestSuite
    • I18n
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class MimeType

MimeType Class

Handles MIME type operations and provides functionality for working with Multipurpose Internet Mail Extensions (MIME) types in the application. This class is responsible for MIME type detection and mapping file extensions to their corresponding MIME types.

Namespace: Cake\Http

Property Summary

  • $mimeTypes protected static
    array<string, array<string>>

    Array of MIME type mappings.

Method Summary

  • addMimeTypes() public static

    Add new mime types for a given file extension.

  • getExtension() public static

    Get the file extension associated with a given MIME type.

  • getMimeType() public static

    Get the MIME type based on the file extension.

  • getMimeTypeForFile() public static

    Get the MIME type for a given file path.

  • getMimeTypes() public static

    Get the MIME types associated with a given file extension.

  • setMimeTypes() public static

    Set MIME types for a given file extension.

Method Detail

addMimeTypes() ¶ public static

addMimeTypes(string $ext, array|string $mimeTypes): void

Add new mime types for a given file extension.

If the file extension already exists, the new mime types will be merged with the existing ones.

Parameters
string $ext

The file extension to associate with the mime types.

array|string $mimeTypes

The mime types to associate with the file extension.

Returns
void

getExtension() ¶ public static

getExtension(string $mimeType): string|null

Get the file extension associated with a given MIME type.

Parameters
string $mimeType

The MIME type for which to get the file extension.

Returns
string|null

getMimeType() ¶ public static

getMimeType(string $ext, string|null $default = null): string|null

Get the MIME type based on the file extension.

Parameters
string $ext

The file extension.

string|null $default optional

The default MIME type to return if the extension is not found. Defaults to null.

Returns
string|null

getMimeTypeForFile() ¶ public static

getMimeTypeForFile(string $path, string $default = 'application/octet-stream'): string

Get the MIME type for a given file path.

If the MIME type is not mapped to an extension then it will attempt to determine the MIME type of the file using the fileinfo extension.

Parameters
string $path

The file path for which to get the MIME type.

string $default optional

The default MIME type to return if the MIME type cannot be determined.

Returns
string

getMimeTypes() ¶ public static

getMimeTypes(string $ext): array|null

Get the MIME types associated with a given file extension.

Parameters
string $ext

The file extension to look up.

Returns
array|null

setMimeTypes() ¶ public static

setMimeTypes(string $ext, array|string $mimeTypes): void

Set MIME types for a given file extension.

This will overwrite any existing MIME types for the file extension.

Parameters
string $ext

The file extension.

array|string $mimeTypes

The MIME types to associate with the file extension.

Returns
void

Property Detail

$mimeTypes ¶ protected static

Array of MIME type mappings.

Associates file extensions with their corresponding MIME type(s). Each key is a file extension (without the dot) and the value is an array of one or more valid MIME types for that extension.

Common MIME types included:

  • Web formats (html, json, xml)
  • Image formats (webp)
  • Feed formats (rss)
  • Application formats (ai, bin, csv, etc.)

Some extensions may map to multiple MIME types, with the first type in the array being the preferred/default type.

Type
array<string, array<string>>
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs