PHP Classes

File: Mime.class.php

Recommend this page to a friend!
  Classes of George Ariton   PHP Valid MIME Type   Mime.class.php   Download  
File: Mime.class.php
Role: Class source
Content type: text/plain
Description: Mime class source
Class: PHP Valid MIME Type
Get the MIME file of file with finfo or file name
Author: By
Last change:
Date: 10 years ago
Size: 3,026 bytes
 

Contents

Class file image Download
<?php
 
/**
   * A class to get header-friendly content-type
   *
   *
   * PHP version 5
   *
   * LICENSE: This source file is subject to version 3.01 of the PHP license
   * that is available through the world-wide-web at the following URI:
   * http://www.php.net/license/3_01.txt. If you did not receive a copy of
   * the PHP License and are unable to obtain it through the web, please
   * send a note to license@php.net so we can mail you a copy immediately.
   *
   * @category Helper
   * @author George Ariton <geo.ariton@gmail.com>
   * @copyright 2008-2013 George Ariton PFA
   * @license http://www.php.net/license/3_01.txt PHP License 3.01
   * @version 1.01
   */
  
 
class Mime {
    private static
$__instance;
 
    var
$mimeTypes = array(
     
'txt' => 'text/plain',
     
'css' => 'text/css',
     
'js' => 'application/javascript',
     
'json' => 'application/json',
     
'xml' => 'application/xml',
     
'swf' => 'application/x-shockwave-flash',
     
'flv' => 'video/x-flv',
 
     
// images
     
'png' => 'image/png',
     
'jpe' => 'image/jpeg',
     
'jpeg' => 'image/jpeg',
     
'jpg' => 'image/jpeg',
     
'gif' => 'image/gif',
     
'bmp' => 'image/bmp',
     
'ico' => 'image/vnd.microsoft.icon',
     
'tiff' => 'image/tiff',
     
'tif' => 'image/tiff',
     
'svg' => 'image/svg+xml',
     
'svgz' => 'image/svg+xml',
 
     
// archives
     
'zip' => 'application/zip',
     
'rar' => 'application/x-rar-compressed',
     
'exe' => 'application/x-msdownload',
     
'msi' => 'application/x-msdownload',
     
'cab' => 'application/vnd.ms-cab-compressed',
 
     
// audio/video
     
'mp3' => 'audio/mpeg',
     
'qt' => 'video/quicktime',
     
'mov' => 'video/quicktime',
 
     
// adobe
     
'pdf' => 'application/pdf',
     
'psd' => 'image/vnd.adobe.photoshop',
     
'ai' => 'application/postscript',
     
'eps' => 'application/postscript',
     
'ps' => 'application/postscript',
 
     
// ms office
     
'doc' => 'application/msword',
     
'rtf' => 'application/rtf',
     
'xls' => 'application/vnd.ms-excel',
     
'ppt' => 'application/vnd.ms-powerpoint',
 
     
// open office
     
'odt' => 'application/vnd.oasis.opendocument.text',
     
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
    );
 
    static function
getInstance() {
      if (
self::$__instance == null) {
       
self::$__instance = new Mime();
      }
      return
self::$__instance;
    }
 
    function
getMimeType($filename) {
     
$ext = strtolower(array_pop(explode('.',$filename)));
      if (
array_key_exists($ext, $this->mimeTypes)) {
        return
$this->mimeTypes[$ext];
      } else if (
function_exists('finfo_open')) {
       
$finfo = finfo_open(FILEINFO_MIME);
       
$mimetype = finfo_file($finfo, $filename);
       
finfo_close($finfo);
        return
$mimetype;
      } else {
        return
'application/octet-stream';
      }
    }
  }
?>