Obtain the file MIME type-PHP source code

Source: Internet
Author: User
Obtain the object MIME type

 'Application/postscript ', 'eps' => 'application/postscript ', 'exe' => 'application/octet-stream', 'Doc' => 'application/vnd. ms-word', 'XLS '=> 'application/vnd. ms-excel ', 'ppt' => 'application/vnd. ms-powerpoint ', 'pps' => 'application/vnd. ms-powerpoint ', 'PDF' => 'application/pdf ', 'xml' => 'application/XML', 'odt' => 'application/vnd. oasis. opendocument. text ', 'swf' => 'application/x-shockwave-Flash', // arch Ives 'gz '=> 'application/x-gzip', 'tgz' => 'application/x-gzip ', 'BZ' => 'application/x-bzip2 ', 'bz2' => 'application/x-bzip2 ', 'tbz' => 'application/x-bzip2', 'Zip' => 'application/zip ', 'rar '=> 'application/x-rar', 'Tar '=> 'application/x-tar', '7z' => 'application/x-7z-compressed ', // texts 'txt '=> 'text/plain', 'php' => 'text/x-php', 'html' => 'text/html ', 'htm '=> 'text/html', 'js' => 'text/javascript ',' Css '=> 'text/css', 'rtf '=> 'text/rtf', 'rtfd '=> 'text/rtfd ', 'py' => 'text/x-Python', 'Java' => 'text/x-java-source ', 'RB' => 'text/x-ruby ', 'sh' => 'text/x-shellscript', 'pl' => 'text/x-perl ', 'SQL' => 'text/x-SQL ', // images 'bmp' => 'image/x-ms-bmp ', 'jpg '=> 'image/jpeg', 'jpeg '=> 'image/jpeg', 'GIF' => 'image/GIF ', 'PNG '=> 'image/png', 'tif '=> 'image/tiff', 'Tiff '=> 'image/tiff ', 'tga '=> 'image/x-targ A', 'psd '=> 'image/vnd. adobe. photoshop ', // audio 'mp3' => 'audio/mpeg', 'mid '=> 'audio/midi', 'ogy' => 'audio/ogc ', 'mp4a '=> 'audio/mp4', 'wav' => 'audio/wav ', 'wm' => 'audio/x-ms-wm ', // video 'Av' => 'video/x-msvideo', 'dv' => 'video/x-DV', 'MP4' => 'video/mp4 ', 'MPEG '=> 'video/mpeg', 'mpg' => 'video/mpeg ', 'mov' => 'video/quicktime ', 'wm '=> 'video/x-ms-wmv', 'flv' => 'video/x-flv', 'mkv '=> 'video/x-matr Oska '); function _ getMimeDetect () {if (class_exists ('finfo') {return 'finfo ';} else if (function_exists ('Mime _ content_type ')) {return 'Mime _ content_type ';} else if (function_exists ('exec') {$ result = exec ('file-ib '. escapeshellarg (_ FILE _); if (0 === strpos ($ result, 'text/x-php') OR 0 === strpos ($ result, 'text/x-c ++ ') {return 'Linux';} $ result = exec ('file-Ib '. escapeshellarg (_ FILE _); if (0 === strpos ($ result, 'text/x-php') OR 0 === strpos ($ result, 'text/x-c ++ ')) {return 'bsd' ;}} return 'internal';} function _ getMimeType ($ path) {global $ mime; $ fmime = _ getMimeDetect (); switch ($ fmime) {case 'finfo': $ finfo = finfo_open (FILEINFO_MIME); if ($ finfo) $ type = @ finfo_file ($ finfo, $ path); break; case 'Mime _ content_type ': $ type = mime_content_type ($ path); break; case 'Linux': $ type = exec ('file-ib '. Escapeshellarg ($ path); break; case 'bsd': $ type = exec ('file-Ib '. escapeshellarg ($ path); break; default: $ pinfo = pathinfo ($ path); $ ext = isset ($ pinfo ['extension'])? Strtolower ($ pinfo ['extension']): ''; $ type = isset ($ mime [$ ext])? $ Mime [$ ext]: 'unkown '; break;} $ type = explode ('; ', $ type); // you need to add this section, if the mime_content_type function is used to obtain a nonexistent $ path, 'application/octet-stream' if ($ fmime! = 'Internal' AND $ type [0] = 'application/octet-stream') {$ pinfo = pathinfo ($ path ); $ ext = isset ($ pinfo ['extension'])? Strtolower ($ pinfo ['extension']): ''; if (! Empty ($ ext) AND! Empty ($ mime [$ ext]) {$ type [0] = $ mime [$ ext] ;}} return $ type [0] ;}$ path = '1.txt '; // 1.txt var_dump (_ getMimeType ($ path) does not exist in the current Shard on the primary node;/* End of php */

The above is the content obtained by the file MIME type. For more information, see PHP Chinese website (www.php1.cn )!

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.