Obtain the mime type based on the file suffix

Source: Internet
Author: User
Tags xslt gtar
Provides various official and user-released code examples and code reference. You are welcome to exchange and learn. /**
* Obtain the mime type based on the file suffix
* @ Param string $ ext file suffix
* @ Return string mime type
*/
Function get_mime_type ($ ext ){
Static $ mime_types = array (
'Apk '=> 'application/vnd. android. package-archive ',
'3gp '=> 'video/3gpp ',
'Ai' => 'application/postscript ',
'Aif' => 'audio/x-aiff ',
'Aifc '=> 'audio/x-aiff ',
'Aiff '=> 'audio/x-aiff ',
'Asc '=> 'text/plain ',
'Atom '=> 'application/atom + xml ',
'Au '=> 'audio/basic ',
'Av' => 'video/x-msvideo ',
'Bcpio' => 'application/x-bcpio ',
'Bin' => 'application/octet-stream ',
'Bmp '=> 'image/bmp ',
'Cdf' => 'application/x-netcdf ',
'Cgm '=> 'image/cgm ',
'Class' => 'application/octet-stream ',
'Cpio' => 'application/x-cpio ',
'Cpt' => 'application/mac-compactpro ',
'Csh' => 'application/x-csh ',
'Css '=> 'text/css ',
'Dcr '=> 'application/x-ctor ',
'Dif '=> 'video/x-dv ',
'Dir' => 'application/x-ctor ',
'Djv' => 'image/vnd. djvu ',
'Djvu '=> 'image/vnd. djvu ',
'Dll '=> 'application/octet-stream ',
'Dmg '=> 'application/octet-stream ',
'Dms '=> 'application/octet-stream ',
'Doc' => 'application/msword ',
'Dtd '=> 'application/xml-dtd ',
'Dv' => 'video/x-dv ',
'Dvi '=> 'application/x-dvi ',
'Dxr' => 'application/x-ctor ',
'Eps '=> 'application/postscript ',
'Etx' => 'text/x-setext ',
'Exe '=> 'application/octet-stream ',
'Ez '=> 'application/andrew-inset ',
'Flv' => 'video/x-flv ',
'Gif' => 'image/gif ',
'Gram '=> 'application/srgs ',
'Grxml' => 'application/srgs + xml ',
'Gtar '=> 'application/x-gtar ',
'Gz '=> 'application/x-gzip ',
'Hdf' => 'application/x-hdf ',
'Hqx' => 'application/mac-binhex40 ',
'Htm '=> 'text/html ',
'Html' => 'text/html ',
'Ice '=> 'x-conference/x-cooltalk ',
'Ico '=> 'image/x-icon ',
'Ics '=> 'text/calendar ',
'Ief' => 'image/ief ',
'Ifb' => 'text/calendar ',
& Apos; iges & apos; = & apos; model/iges & apos ',
'Gies' => 'model/iges ',
'Jnlp '=> 'application/x-java-jnlp-file ',
'Jp2' => 'image/jp2 ',
'Jpe' => 'image/jpeg ',
'Jpeg '=> 'image/jpeg ',
'Jpg '=> 'image/jpeg ',
'Js' => 'application/x-javascript ',
'Kar '=> 'audio/midi ',
'Latex '=> 'application/x-latex ',
'Lha' => 'application/octet-stream ',
'Lzh '=> 'application/octet-stream ',
'M3u' => 'audio/x-mpegurl ',
'M4a '=> 'audio/mp4a-latm ',
'M4p' => 'audio/mp4a-latm ',
'M4u' => 'video/vnd. mpegurl ',
'M4' => 'video/x-m4v ',
'Mac' => 'image/x-macpa ',
'Man '=> 'application/x-troff-man ',
'Mathm' => 'application/mathml + xml ',
'Me' => 'application/x-troff-me ',
'Mesh '=> 'model/mesh ',
'Mid '=> 'audio/midi ',
'Midi '=> 'audio/midi ',
'Mfa' => 'application/vnd. mfa ',
'Mov' => 'video/quicktime ',
'Movi' => 'video/x-sgi-movi ',
'Mp2' => 'audio/mpeg ',
'Mp3' => 'audio/mpeg ',
'Mp4' => 'video/mp4 ',
'Mpe' => 'video/mpeg ',
'Mpeg '=> 'video/mpeg ',
'Mpg' => 'video/mpeg ',
'Mpga' => 'audio/mpeg ',
'Ms' => 'application/x-troff-Ms ',
'Msh' => 'model/mesh ',
'Mxu' => 'video/vnd. mpegurl ',
'Nc '=> 'application/x-netcdf ',
'Oda '=> 'application/oda ',
'Ogc' => 'application/ogc ',
'Ogv' => 'video/ogv ',
'Pbm' => 'image/x-portable-bitmap ',
'Pct '=> 'image/pict ',
'Pdb' => 'chemical/x-pdb ',
'Pdf '=> 'application/pdf ',
'Pgm '=> 'image/x-portable-graymap ',
'Pgn' => 'application/x-chess-pgn ',
'Pic '=> 'image/pict ',
'Pict' => 'image/pict ',
'Png '=> 'image/png ',
'Pnm '=> 'image/x-portable-anymap ',
'Pnt '=> 'image/x-macpa ',
'Png' => 'image/x-macpa ',
'Ppm '=> 'image/x-portable-pixmap ',
'Ppt '=> 'application/vnd. ms-powerpoint ',
'Ps '=> 'application/postscript ',
'Qt '=> 'video/quicktime ',
'Qti' => 'image/x-quicktime ',
'Qtif '=> 'image/x-quicktime ',
'A' => 'audio/x-pn-realaudio ',
'Ram '=> 'audio/x-pn-realaudio ',
'Ras '=> 'image/x-cmu-raster ',
'Rdf '=> 'application/rdf + xml ',
'Rgb '=> 'image/x-rgb ',
'Rm '=> 'application/vnd. rn-realmedia ',
'Roff' => 'application/x-troff ',
'Rtf '=> 'text/rtf ',
'Rtx' => 'text/richtext ',
'Sgm' => 'text/sgml ',
'Sgml' => 'text/sgml ',
'Sh' => 'application/x-Sh ',
'Shar '=> 'application/x-shar ',
'Silo' => 'model/mesh ',
'Sit '=> 'application/x-stuffit ',
'Skd' => 'application/x-koan ',
'Skm' => 'application/x-koan ',
'Skp' => 'application/x-koan ',
'Skt' => 'application/x-koan ',
'Smi' => 'application/smil ',
'Smil '=> 'application/smil ',
'Snd' => 'audio/basic ',
'So' => 'application/octet-stream ',
'Spl' => 'application/x-futuresplash ',
'Src' => 'application/x-wais-source ',
'Sv4cpio '=> 'application/x-sv4cpio ',
'Sv4crc '=> 'application/x-sv4crc ',
'Svg '=> 'image/svg + xml ',
'Swf '=> 'application/x-shockwave-flash ',
'T' => 'application/x-troff ',
'Tar '=> 'application/x-tar ',
'Tcl '=> 'application/x-tcl ',
'Tex '=> 'application/x-tex ',
'Text' => 'application/x-textinfo ',
'Textinfo' => 'application/x-textinfo ',
'Tif '=> 'image/tiff ',
'Tiff '=> 'image/tiff ',
'Tr' => 'application/x-troff ',
'Tsv' => 'text/tab-separated-values ',
'Txt '=> 'text/plain ',
'Ustar' => 'application/x-ustar ',
'Vcd' => 'application/x-cdlink ',
'Jpa' => 'model/jpa ',
'Vxml' => 'application/voicexml + xml ',
'Wav '=> 'audio/x-wav ',
'Wbmp '=> 'image/vnd. wap. wbmp ',
'Wbxml' => 'application/vnd. wap. wbxml ',
'Webm' => 'video/webm ',
'Wml' => 'text/vnd. wap. wml ',
'Wmlc' => 'application/vnd. wap. wmlc ',
'Wmls' => 'text/vnd. wap. wmlscript ',
'Wmlsc '=> 'application/vnd. wap. wmlscriptc ',
'Wmv '=> 'video/x-ms-wmv ',
'Wrl' => 'model/jpa ',
'Xbm '=> 'image/x-xbitmap ',
'Xht '=> 'application/xhtml + xml ',
'Xhtml '=> 'application/xhtml + xml ',
'Xls '=> 'application/vnd. ms-excel ',
'Xml' => 'application/xml ',
'Xpm' => 'image/x-xpixmap ',
'Xsl '=> 'application/xml ',
'Xslt '=> 'application/xslt + xml ',
'Xul '=> 'application/vnd. mozilla. xul + xml ',
'Xwd '=> 'image/x-xwindowdump ',
'Xyz' => 'chemical/x-xyz ',
'Zip' => 'application/zip'
);

Return isset ($ mime_types [$ ext])? $ Mime_types [$ ext]: 'application/octet-stream ';
}

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.