Signature <? Php $ Mime = array ( // Applications 'AI' => '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 ', // Archives 'Gz '=> 'application/x-gzip ', 'Tgz' => 'application/x-gzip ', 'Yz' => '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 ', 'Rtfs' => 'text/rtfs ', '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-targa ', 'Psd '=> 'image/vnd. adobe. photoshop ', // Audio 'Mp3' => 'audio/mpeg ', 'Mid '=> 'audio/midi ', 'Ogc' => 'audio/ogc ', 'Mp4a '=> 'audio/mp4 ', 'Wav '=> 'audio/wav ', 'Wma' => 'audio/x-ms-wma ', // 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-matroska' ); 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 ); // This section needs to be added, because if the mime_content_type function is used to obtain a nonexistent $ path, 'application/octet-stream' will be returned' 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 '; // the current cursor does not exist in 1.txt Var_dump (_ getMimeType ($ path )); /* End of php */ |