code: private function detectMimeType($file)
      {
          $fileParts = explode('.', $file);
          $extension = array_pop($fileParts);
          $extension = strtolower($extension);
  
          if (array_key_exists($extension, $this->mimeTypes)) {
              return $this->mimeTypes[$extension];
          }
  
          if (function_exists('finfo_open')) {
              $finfo    = finfo_open(FILEINFO_MIME_TYPE);
              $mimeType = finfo_file($finfo, $file);
              finfo_close($finfo);
  
              return $mimeType;
          }
  
          return 'application/octet-stream';
      }
docs: Detects file mime type from extension or using finfo_file if exists.
  
  @param string $file the file to examine
  @return string the mime type