Zubrag.com :: Forum

Programmers Lounge => Tips and Tricks => Topic started by: zubrag on January 26, 2007, 04:12:01 PM



Title: mime type detection on php
Post by: zubrag on January 26, 2007, 04:12:01 PM
  $mtype = '';

  // magic_mime module installed?
  if (function_exists('mime_content_type')) {
    $mtype = mime_content_type($file_path);
  }
  // fileinfo module installed?
  else if (function_exists('finfo_file')) {
    $finfo = finfo_open(FILEINFO_MIME); // return mime type
    $mtype = finfo_file($finfo, $file_path);
    finfo_close($finfo); 
  }

Note: this code tries to use magic_mime or fileinfo module for mime type detection. Some hosters does not have these modules installed.