1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26-27--28 29---30 31--32 33 34 35 36 37 38-39 40 41 42 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 5, 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 11 9 120 121 122 |
<?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 ', ' BZ ' => ' N/x-bzip2 ', ' bz2 ' => ' application/x-bzip2 ', ' tbz ' => ' application/x-bzip2 ', ' Zip ' => ' application/zip ', ' rar ' =& Gt ' Application/x-rar ', ' tar ' => ' application/x-tar ', ' 7z ' => ' application/x-7z-compressed ',//texts ' txt ' => ' Tex T/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 ' =& Gt ' Text/x-shellscript ', ' pl ' => ' text/x-perl ', ' sql ' => ' text/x-sql ',//images ' bmp ' => ' image/x-ms-bmp ', ' jpg ' =& Gt ' 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 ' => ' G ', ' mid ' => ' Audio/midi ', ' ogg ' => ' Audio/ogg ', ' mp4a ' => ' audio/mp4 ', ' wav ' => ' audio/wav ', ' wma ' => ' AUD Io/x-ms-wma ',//Video ' avi ' => ' video/x-msvideo ', ' dv ' => ' VIDEO/X-DV ', ' mp4 ' => ' video/mp4 ', ' mpeg ' => ' vide O/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 '. Escapesh Ellarg (__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_op En (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 because if you use the Mime_content_type function to get a nonexistent $path, you will return ' 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 '; In fact, the current path does not exist 1. txt var_dump (_getmimetype ($path)); /*end of php*/ |