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 */ |