PHP code example of fileeye / mimemap

1. Go to this page and download the library: Download fileeye/mimemap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

fileeye / mimemap example snippets


  use FileEye\MimeMap\Type;
  ...
  $type = new Type('image/jpeg');

  print_r($type->getExtensions());
  // will print ['jpeg', 'jpg', 'jpe']

  print_r($type->getDefaultExtension());
  // will print 'jpeg'

  // When passing an alias to a MIME type, the API will
  // return the extensions to the parent type:
  $type = new Type('image/pdf');

  print_r($type->getDefaultExtension());
  // will print 'pdf' which is the default extension for 'application/pdf'
  

  use FileEye\MimeMap\Extension;
  ...
  $ext = new Extension('xar');

  print_r($ext->getTypes());
  // will return ['application/vnd.xara', 'application/x-xar']

  print_r($ext->getDefaultType());
  // will return 'application/vnd.xara'
  

  use FileEye\MimeMap\Type;
  ...
  $type = new Type('text / (Unstructured text)  plain  ; charset = (UTF8, not ASCII) utf-8');
  $type->addParameter('lang', 'it', 'Italian');

  echo $type->toString(Type::SHORT_TEXT);
  // will print 'text/plain'

  echo $type->toString(Type::FULL_TEXT);
  // will print 'text/plain; charset="utf-8"; lang="it"'

  echo $type->toString(Type::FULL_TEXT_WITH_COMMENTS);
  // will print 'text/plain (Unstructured text); charset="utf-8" (UTF8, not ASCII), lang="it" (Italian)'
  

  use FileEye\MimeMap\Type;
  ...
  $type = new Type('text/html');

  $type_desc = $type->getDescription();
  $type->setSubTypeComment($type_desc);
  echo $type->toString(Type::FULL_TEXT_WITH_COMMENTS);
  // will print 'text/html (HTML document)'

  // Setting the $ext Markup Language)'
  

  use FileEye\MimeMap\Extension;
  use FileEye\MimeMap\MapHandler;
  use FileEye\MimeMap\Type;
  ...
  $map = MapHandler::map();
  $map->addTypeExtensionMapping('foo/bar', 'baz');

  $type = new Type('foo/bar');
  $default_extension = $type->getDefaultExtension();
  // will return 'baz'

  $ext = new Extension('baz');
  $default_type = $ext->getDefaultExtension();
  // will return 'foo/bar'
  

  use FileEye\MimeMap\Extension;
  use FileEye\MimeMap\MapHandler;
  use FileEye\MimeMap\Type;
  ...
  MapHandler::setDefaultMapClass('MyProject\MyMap');
  ...
  

  use FileEye\MimeMap\Extension;
  use FileEye\MimeMap\Type;
  ...
  $type = new Type('foo/bar', 'MyProject\MyMap');
  $ext = new Extension('baz', 'MyProject\MyMap');