sanitize_mime_type()WP 3.1.3

Sanitize a mime type

1 time — 0.000049 sec (very fast) | 50000 times — 0.04 sec (speed of light)
Hooks from the function

Return

String. Sanitized mime type.

Usage

sanitize_mime_type( $mime_type );
$mime_type(string) (required)
Mime type.

Examples

0

#1 MIME type cleaning demonstration

$mine = sanitize_mime_type( 'audio / vnd.wave' );

echo $mine; // audio/vnd.wave
$mimetype = sanitize_mime_type( 'typeexample1-_/[]{}.pdf' );

echo $mimetype; // typeexample1-/.pdf
0

#2 MIME types list

See the entire list of mime types here.

application
Internal format of the application program
application/atom+xml: Atom
application/EDI-X12: EDI X12
application/EDIFACT: EDI EDIFACT
application/json: JavaScript Object Notation JSON
application/javascript: JavaScript
application/octet-stream: Binary file with no format specification
application/ogg: Ogg
application/pdf: Portable Document Format, PDF
application/postscript: PostScript
application/soap+xml: SOAP
application/x-woff: Web Open Font Format
application/xhtml+xml: XHTML
application/xml-dtd: DTD
application/xop+xml:XOP
application/zip: ZIP
application/gzip: Gzip
application/x-bittorrent: BitTorrent
application/x-tex: TeX
audio
Audio
audio/basic: mulaw audio, 8 kHz, 1 channel
audio/L24: 24bit Linear PCM audio, 8-48 kHz, 1-N channels
audio/mp4: MP4
audio/aac: AAC
audio/mpeg: MP3 or other. MPEG
audio/ogg: Ogg Vorbis, Speex, Flac or other audio
audio/vorbis: Vorbis
audio/x-ms-wma: Windows Media Audio
audio/x-ms-wax: Windows Media Audio redirection
audio/vnd.rn-realaudio: RealAudio
audio/vnd.wave: WAV
audio/webm: WebM
image
Image
image/gif: GIF
image/jpeg: JPEG
image/pjpeg: JPEG
image/png: Portable Network Graphics
image/svg+xml: SVG
image/tiff: TIFF
image/vnd.microsoft.icon: ICO
image/vnd.wap.wbmp: WBMP
message
Message
message/http:
message/imdn+xml: IMDN
message/partial: E-mail
message/rfc822: E-mail; EML files, MIME files, MHT files, MHTML files
model
for 3D models
model/example:
model/iges: IGS files, IGES files
model/mesh: MSH files, MESH files, SILO files
model/vrml: WRL files, VRML files
model/x3d+binary: X3D ISO standard for 3D computer graphics, X3DB files
model/x3d+vrml: X3D ISO standard for 3D computer graphics, X3DV VRML files
model/x3d+xml: X3D ISO standard for 3D computer graphics, X3D XML files
multipart
multipart/mixed: MIME E-mail
multipart/alternative: MIME E-mail
multipart/related: MIME E-mail
multipart/form-data: MIME Webform
multipart/signed:
multipart/encrypted:
text
Text
text/cmd: Commands
text/css: Cascading Style Sheets
text/csv: CSV
text/html: HTML
text/javascript (Obsolete): JavaScript
text/plain: text data
text/php: PHP language script
text/xml: Extensible Markup Language
video
Video
video/mpeg: MPEG-1
video/mp4: MP4
video/ogg: Ogg Theora or other video
video/quicktime: QuickTime
video/webm: WebM
video/x-ms-wmv: Windows Media Video
video/x-flv: FLV
video/3gpp: .3gpp .3gp
video/3gpp2: .3gpp2 .3g2
vnd
Vendor files
application/vnd.oasis.opendocument.text: OpenDocument
application/vnd.oasis.opendocument.spreadsheet: OpenDocument
application/vnd.oasis.opendocument.presentation: OpenDocument
application/vnd.oasis.opendocument.graphics: OpenDocument
application/vnd.ms-excel: Microsoft Excel files
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet: Microsoft Excel 2007 files
application/vnd.ms-powerpoint: Microsoft Powerpoint files
application/vnd.openxmlformats-officedocument.presentationml.presentation: Microsoft Powerpoint 2007 files
application/msword: Microsoft Word files
application/vnd.openxmlformats-officedocument.wordprocessingml.document: Microsoft Word 2007 files
application/vnd.mozilla.xul+xml: Mozilla XUL files
application/vnd.google-earth.kml+xml: KML files (e.g. for Google Earth)
x
Non-standard files
application/x-www-form-urlencoded: Form Encoded Data
application/x-dvi: DVI
application/x-latex: LaTeX files
application/x-font-ttf: TrueType (not a registered MIME type, but most commonly used)
application/x-shockwave-flash: Adobe Flash and
application/x-stuffit: StuffIt
application/x-rar-compressed: RAR
application/x-tar: Tarball
text/x-jquery-tmpl: jQuery
application/x-javascript:
x-pkcs
PKCS
application/x-pkcs12: p12 files
application/x-pkcs12: pfx files
application/x-pkcs7-certificates: p7b files
application/x-pkcs7-certificates: spc files
application/x-pkcs7-certreqresp: p7r files
application/x-pkcs7-mime: p7c files
application/x-pkcs7-mime: p7m files
application/x-pkcs7-signature: p7s files

Changelog

Since 3.1.3 Introduced.

sanitize_mime_type() code WP 6.5.2

function sanitize_mime_type( $mime_type ) {
	$sani_mime_type = preg_replace( '/[^-+*.a-zA-Z0-9\/]/', '', $mime_type );
	/**
	 * Filters a mime type following sanitization.
	 *
	 * @since 3.1.3
	 *
	 * @param string $sani_mime_type The sanitized mime type.
	 * @param string $mime_type      The mime type prior to sanitization.
	 */
	return apply_filters( 'sanitize_mime_type', $sani_mime_type, $mime_type );
}