Advertisement
AlexanderNorup

PhP Mime Type

Apr 18th, 2016
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.18 KB | None | 0 0
  1. function mime_content_type2($filename) {
  2.  
  3.     $mime_types = array(
  4.  
  5.         'txt' => 'text/plain',
  6.         'htm' => 'text/html',
  7.         'html' => 'text/html',
  8.         'php' => 'text/html',
  9.         'css' => 'text/css',
  10.         'js' => 'application/javascript',
  11.         'json' => 'application/json',
  12.         'xml' => 'application/xml',
  13.         'swf' => 'application/x-shockwave-flash',
  14.         'flv' => 'video/x-flv',
  15.  
  16.         // images
  17.         'png' => 'image/png',
  18.         'jpe' => 'image/jpeg',
  19.         'jpeg' => 'image/jpeg',
  20.         'jpg' => 'image/jpeg',
  21.         'gif' => 'image/gif',
  22.         'bmp' => 'image/bmp',
  23.         'ico' => 'image/vnd.microsoft.icon',
  24.         'tiff' => 'image/tiff',
  25.         'tif' => 'image/tiff',
  26.         'svg' => 'image/svg+xml',
  27.         'svgz' => 'image/svg+xml',
  28.  
  29.         // archives
  30.         'zip' => 'application/zip',
  31.         'rar' => 'application/x-rar-compressed',
  32.         'exe' => 'application/x-msdownload',
  33.         'msi' => 'application/x-msdownload',
  34.         'cab' => 'application/vnd.ms-cab-compressed',
  35.  
  36.         // audio/video
  37.         'mp3' => 'audio/mpeg',
  38.         'qt' => 'video/quicktime',
  39.         'mov' => 'video/quicktime',
  40.  
  41.         // adobe
  42.         'pdf' => 'application/pdf',
  43.         'psd' => 'image/vnd.adobe.photoshop',
  44.         'ai' => 'application/postscript',
  45.         'eps' => 'application/postscript',
  46.         'ps' => 'application/postscript',
  47.  
  48.         // ms office
  49.         'doc' => 'application/msword',
  50.         'rtf' => 'application/rtf',
  51.         'xls' => 'application/vnd.ms-excel',
  52.         'ppt' => 'application/vnd.ms-powerpoint',
  53.  
  54.         // open office
  55.         'odt' => 'application/vnd.oasis.opendocument.text',
  56.         'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
  57.     );
  58.  
  59.     $ext = strtolower(array_pop(explode('.',$filename)));
  60.     if (array_key_exists($ext, $mime_types)) {
  61.         return $mime_types[$ext];
  62.     }
  63.     elseif (function_exists('finfo_open')) {
  64.         $finfo = finfo_open(FILEINFO_MIME);
  65.         $mimetype = finfo_file($finfo, $filename);
  66.         finfo_close($finfo);
  67.         return $mimetype;
  68.     }
  69.     else {
  70.         return 'application/octet-stream';
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement