You are here

README.txt in MimeDetect 8

Same filename and directory in other branches
  1. 5 README.txt
  2. 6 README.txt
  3. 7 README.txt
MIMEDETECT DRUPAL MODULE
========================

CONTENTS OF THIS FILE
---------------------

 * Summary
 * Requirements
 * Installation
 * Configuration
 * Usage
 * Recommended modules
 * Troubleshooting
 * Contact
 * Credits


SUMMARY
-------

MimeDetect provides a MIME detection API. Detection itself is done following
these steps:

 1. MIME detection plugins
    If a detection plugin for the given filename extension exists, it is
    executed. When MIME detection by plugins succeeds, the detected MIME type
    is returned and no more methods will be tested.

 2. Fileinfo PHP extension
    Used if enabled (in config) and such PHP extension is available in your
    system. Detection will stop here when a result different from the generic
    "application/octet-stream" is obtained.

 3. UNIX file command
    Disabled by default, it is used when present.

 4. Core MIME type guesser is used as a fallback.
    This is the default MIME type dectection in Drupal and is based only on
    a mapping between filename extensions and the corresponding MIME types.

MimeDetect also includes a submodule for file upload protection against
inconsistent filename extension with its real content.


REQUIREMENTS
------------

At least one of these two supported tools based on MIME 'magic' detection has to
be present in your system:

 1. PHP File information extension
    Commonly included in the basic PHP installation.
    see: http://php.net/manual/en/book.fileinfo.php

 2. UNIX 'file' command
    Present on most UNIX/Linux systems.
    see: https://en.wikipedia.org/wiki/File_(command)


INSTALLATION
------------

Install as usual, see https://www.drupal.org/node/1897420 for further
information.


CONFIGURATION
-------------

Module configuration is available at Manage -> Configuration -> Media
(/admin/config/media/mimedetect).

By default, only the PHP fileinfo detection engine is enabled.


USAGE
-----

MimeDetect acts as an API, other modules can make usage of it by using the
'mimedetect' service.

A simple file upload validator is included in a separate module for illustration
purposes, basic functionality and backward compatibility with Drupal 6 & 7. It
rejects any file upload which detected MIME type doesn't match the filename
extension.


RECOMMENDED MODULES
-------------------

 * File MIME (https://www.drupal.org/project/filemime):
   Provides a way to alter the core MIME type mapping to file name extensions.
   Use it to add unrecognized extensions or to alter the MIME associated with
   some particular extension.


MIME DETECTION PLUGINS
----------------------

Not all file content types can be determined by MIME 'magic' method. In such
cases a programmatic method has to be implemented as a plugin. For example, CSV
files are detected as "text/plain" by the PHP fileinfo or the file UNIX
command. MimeDetect comes with a plugin to detect CSV files by examining their
real content.


TROUBLESHOOTING
---------------

File upload validation with unrecognized file name extensions:

Drupal core maps each file extension with a MIME type. Thats the way the
"file.mime_type.guesser" service guesses the MIME type for a given file name.

Some file name extensions are not present on such map or can be mapped with a
different MIME type than the detected by MimeDetect. For example, that's the
case for portable object (".po") files. PO files are plain text files that
contain translation strings. Drupal core returns the generic
'application/octet-stream' MIME type for them, whereas 'magic' MIME detection
engines (and therefore MimeDetect) usually returns 'text/x-po' as the detected
MIME type.

This mismatch will make file upload validator to block file uploading. The
right way to solve this is by altering the Drupal core file name extension map,
adding the unrecognized MIME types or overriding existing ones. And that's
exactly what the filemime recommended module does, so you will find this module
useful to solve these scenarios.


CONTACT
-------

Current maintainers:
* Manuel Adan (manuel.adan) - https://www.drupal.org/user/516420


CREDITS
-------

Ported to D8 by:
* Manuel Adan (manuel.adan) - https://www.drupal.org/user/516420

Ported to D6 & D7 by:
* andrew morton (drewish) - https://www.drupal.org/user/34869

Created by:
* Darrel O'Pry (dopry) - https://www.drupal.org/user/22202

File

README.txt
View source
  1. MIMEDETECT DRUPAL MODULE
  2. ========================
  3. CONTENTS OF THIS FILE
  4. ---------------------
  5. * Summary
  6. * Requirements
  7. * Installation
  8. * Configuration
  9. * Usage
  10. * Recommended modules
  11. * Troubleshooting
  12. * Contact
  13. * Credits
  14. SUMMARY
  15. -------
  16. MimeDetect provides a MIME detection API. Detection itself is done following
  17. these steps:
  18. 1. MIME detection plugins
  19. If a detection plugin for the given filename extension exists, it is
  20. executed. When MIME detection by plugins succeeds, the detected MIME type
  21. is returned and no more methods will be tested.
  22. 2. Fileinfo PHP extension
  23. Used if enabled (in config) and such PHP extension is available in your
  24. system. Detection will stop here when a result different from the generic
  25. "application/octet-stream" is obtained.
  26. 3. UNIX file command
  27. Disabled by default, it is used when present.
  28. 4. Core MIME type guesser is used as a fallback.
  29. This is the default MIME type dectection in Drupal and is based only on
  30. a mapping between filename extensions and the corresponding MIME types.
  31. MimeDetect also includes a submodule for file upload protection against
  32. inconsistent filename extension with its real content.
  33. REQUIREMENTS
  34. ------------
  35. At least one of these two supported tools based on MIME 'magic' detection has to
  36. be present in your system:
  37. 1. PHP File information extension
  38. Commonly included in the basic PHP installation.
  39. see: http://php.net/manual/en/book.fileinfo.php
  40. 2. UNIX 'file' command
  41. Present on most UNIX/Linux systems.
  42. see: https://en.wikipedia.org/wiki/File_(command)
  43. INSTALLATION
  44. ------------
  45. Install as usual, see https://www.drupal.org/node/1897420 for further
  46. information.
  47. CONFIGURATION
  48. -------------
  49. Module configuration is available at Manage -> Configuration -> Media
  50. (/admin/config/media/mimedetect).
  51. By default, only the PHP fileinfo detection engine is enabled.
  52. USAGE
  53. -----
  54. MimeDetect acts as an API, other modules can make usage of it by using the
  55. 'mimedetect' service.
  56. A simple file upload validator is included in a separate module for illustration
  57. purposes, basic functionality and backward compatibility with Drupal 6 & 7. It
  58. rejects any file upload which detected MIME type doesn't match the filename
  59. extension.
  60. RECOMMENDED MODULES
  61. -------------------
  62. * File MIME (https://www.drupal.org/project/filemime):
  63. Provides a way to alter the core MIME type mapping to file name extensions.
  64. Use it to add unrecognized extensions or to alter the MIME associated with
  65. some particular extension.
  66. MIME DETECTION PLUGINS
  67. ----------------------
  68. Not all file content types can be determined by MIME 'magic' method. In such
  69. cases a programmatic method has to be implemented as a plugin. For example, CSV
  70. files are detected as "text/plain" by the PHP fileinfo or the file UNIX
  71. command. MimeDetect comes with a plugin to detect CSV files by examining their
  72. real content.
  73. TROUBLESHOOTING
  74. ---------------
  75. File upload validation with unrecognized file name extensions:
  76. Drupal core maps each file extension with a MIME type. Thats the way the
  77. "file.mime_type.guesser" service guesses the MIME type for a given file name.
  78. Some file name extensions are not present on such map or can be mapped with a
  79. different MIME type than the detected by MimeDetect. For example, that's the
  80. case for portable object (".po") files. PO files are plain text files that
  81. contain translation strings. Drupal core returns the generic
  82. 'application/octet-stream' MIME type for them, whereas 'magic' MIME detection
  83. engines (and therefore MimeDetect) usually returns 'text/x-po' as the detected
  84. MIME type.
  85. This mismatch will make file upload validator to block file uploading. The
  86. right way to solve this is by altering the Drupal core file name extension map,
  87. adding the unrecognized MIME types or overriding existing ones. And that's
  88. exactly what the filemime recommended module does, so you will find this module
  89. useful to solve these scenarios.
  90. CONTACT
  91. -------
  92. Current maintainers:
  93. * Manuel Adan (manuel.adan) - https://www.drupal.org/user/516420
  94. CREDITS
  95. -------
  96. Ported to D8 by:
  97. * Manuel Adan (manuel.adan) - https://www.drupal.org/user/516420
  98. Ported to D6 & D7 by:
  99. * andrew morton (drewish) - https://www.drupal.org/user/34869
  100. Created by:
  101. * Darrel O'Pry (dopry) - https://www.drupal.org/user/22202