{
    "mode": "perldoc",
    "parameter": "MIME::Types",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/MIME%3A%3ATypes/json",
    "generated": "2026-05-30T10:44:22Z",
    "synopsis": "use MIME::Types;\nmy $mt    = MIME::Types->new(...);    # MIME::Types object\nmy $type  = $mt->type('text/plain');  # MIME::Type  object\nmy $type  = $mt->mimeTypeOf('gif');\nmy $type  = $mt->mimeTypeOf('picture.jpg');\nmy @types = $mt->httpAccept('text/html, application/json;q=0.1')",
    "sections": {
        "NAME": {
            "content": "MIME::Types - Definition of MIME types\n",
            "subsections": []
        },
        "INHERITANCE": {
            "content": "MIME::Types\nis a Exporter\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use MIME::Types;\nmy $mt    = MIME::Types->new(...);    # MIME::Types object\nmy $type  = $mt->type('text/plain');  # MIME::Type  object\nmy $type  = $mt->mimeTypeOf('gif');\nmy $type  = $mt->mimeTypeOf('picture.jpg');\nmy @types = $mt->httpAccept('text/html, application/json;q=0.1')\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "MIME types are used in many applications (for instance as part of e-mail\nand HTTP traffic) to indicate the type of content which is transmitted.\nor expected. See RFC2045 at https://www.ietf.org/rfc/rfc2045.txt\n\nSometimes detailed knowledge about a mime-type is need, however this\nmodule only knows about the file-name extensions which relate to some\nfiletype. It can also be used to produce the right format: types which\nare not registered at IANA need to use 'x-' prefixes.\n\nThis object administers a huge list of known mime-types, combined from\nvarious sources. For instance, it contains all IANA types and the\nknowledge of Apache. Probably the most complete table on the net!\n\nMIME::Types and daemons (fork)\nIf your program uses fork (usually for a daemon), then you want to have\nthe type table initialized before you start forking. So, first call\n\nmy $mt = MIME::Types->new;\n\nLater, each time you create this object (you may, of course, also reuse\nthe object you create here) you will get access to the same global table\nof types.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "",
            "subsections": [
                {
                    "name": "Constructors",
                    "content": "MIME::Types->new(%options)\nCreate a new \"MIME::Types\" object which manages the data. In the\ncurrent implementation, it does not matter whether you create this\nobject often within your program, but in the future this may change.\n\n-Option         --Default\ndbfile          <installed source>\nonlycomplete    <false>\nonlyiana        <false>\nskipextensions  <false>\n\ndbfile => FILENAME\nThe location of the database which contains the type information.\nOnly the first instantiation of this object will have this\nparameter obeyed.\n\n[2.10] This parameter can be globally overruled via the\n\"PERLMIMETYPEDB\" environment variable, which may be needed in\ncase of PAR or other tricky installations. For PAR, you probably\nset this environment variable to \"inc/lib/MIME/types.db\"\n\nonlycomplete => BOOLEAN\nOnly include complete MIME type definitions: requires at least one\nknown extension. This will reduce the number of entries --and with\nthat the amount of memory consumed-- considerably.\n\nIn your program you have to decide: the first time that you call\nthe creator (\"new\") determines whether you get the full or the\npartial information.\n\nonlyiana => BOOLEAN\nOnly load the types which are currently known by IANA.\n\nskipextensions => BOOLEAN\nDo not load the table to map extensions to types, which is quite\nlarge.\n"
                },
                {
                    "name": "Knowledge",
                    "content": "$obj->addType($type, ...)\nAdd one or more TYPEs to the set of known types. Each TYPE is a\n\"MIME::Type\" which must be experimental: either the main-type or the\nsub-type must start with \"x-\".\n\nPlease inform the maintainer of this module when registered types\nare missing. Before version MIME::Types version 1.14, a warning was\nproduced when an unknown IANA type was added. This has been removed,\nbecause some people need that to get their application to work\nlocally... broken applications...\n\n$obj->extensions()\nReturns a list of all defined extensions.\n\n$obj->listTypes()\nReturns a list of all defined mime-types by name only. This will not\ninstantiate MIME::Type objects. See types()\n\n$obj->mimeTypeOf($filename)\nReturns the \"MIME::Type\" object which belongs to the FILENAME (or\nsimply its filename extension) or \"undef\" if the file type is\nunknown. The extension is used and considered case-insensitive.\n\nIn some cases, more than one type is known for a certain filename\nextension. In that case, the preferred one is taken (for an unclear\ndefinition of preference)\n\nexample: use of mimeTypeOf()\n\nmy $types = MIME::Types->new;\nmy $mime = $types->mimeTypeOf('gif');\n\nmy $mime = $types->mimeTypeOf('picture.jpg');\nprint $mime->isBinary;\n\n$obj->type($string)\nReturns the \"MIME::Type\" which describes the type related to STRING.\n[2.00] Only one type will be returned.\n\n[before 2.00] One type may be described more than once. Different\nextensions may be in use for this type, and different operating\nsystems may cause more than one \"MIME::Type\" object to be defined.\nIn scalar context, only the first is returned.\n\n$obj->types()\nReturns a list of all defined mime-types. For reasons of backwards\ncompatibility, this will instantiate MIME::Type objects, which will\nbe returned. See listTypes().\n\nHTTP support\n$obj->httpAccept($header)\n[2.07] Decompose a typical HTTP-Accept header, and sort it based on\nthe included priority information. Returned is a sorted list of type\nnames, where the highest priority type is first. The list may\ncontain '*/*' (accept any) or a '*' as subtype.\n\nIll-formated typenames are ignored. On equal qualities, the order is\nkept. See RFC2616 section 14.1\n\nexample:\n\nmy @types = $types->httpAccept('text/html, application/json;q=0.9');\n\n$obj->httpAcceptBest($accept|\\@types, @have)\n[2.07] The $accept string is processed via httpAccept() to order the\ntypes on preference. You may also provide a list of ordered @types\nwhich may have been the result of that method, called earlier.\n\nAs second parameter, you pass a LIST of types you @have to offer.\nThose need to be MIME::Type objects. The preferred type will get\nselected. When none of these are accepted by the client, this will\nreturn \"undef\". It should result in a 406 server response.\n\nexample:\n\nmy $accept = $req->header('Accept');\nmy @have   = map $mt->type($), qw[text/plain text/html];\nmy @ext    = $mt->httpAcceptBest($accept, @have);\n\n$obj->httpAcceptSelect($accept|\\@types, @filenames|\\@filenames)\n[2.07] Like httpAcceptBest(), but now we do not return a pair with\nmime-type and filename, not just the type. If $accept is \"undef\",\nthe first filename is returned.\n\nexample:\n\nuse HTTP::Status ':constants';\nuse File::Glob   'bsdglob';    # understands blanks in filename\n\nmy @filenames   = bsdglob \"$imagedir/$fnbase.*;\nmy $accept      = $req->header('Accept');\nmy ($fn, $mime) = $mt->httpAcceptSelect($accept, @filenames);\nmy $code        = defined $mime ? HTTPNOTACCEPTABLE : HTTPOK;\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "The next functions are provided for backward compatibility with\nMIME::Types versions [0.06] and below. This code originates from Jeff\nOkamoto okamoto@corp.hp.com and others.\n\nbymediatype(TYPE)\nThis function takes a media type and returns a list or anonymous\narray of anonymous three-element arrays whose values are the file\nname suffix used to identify it, the media type, and a content\nencoding.\n\nTYPE can be a full type name (contains '/', and will be matched in\nfull), a partial type (which is used as regular expression) or a\nreal regular expression.\n\nbysuffix(FILENAME|SUFFIX)\nLike \"mimeTypeOf\", but does not return an \"MIME::Type\" object. If\nthe file +type is unknown, both the returned media type and encoding\nare empty strings.\n\nexample: use of function bysuffix()\n\nuse MIME::Types 'bysuffix';\nmy ($mediatype, $encoding) = bysuffix('image.gif');\n\nmy $refdata = bysuffix('image.gif');\nmy ($mediatype, $encoding) = @$refdata;\n\nimportmimetypes()\nThis method has been removed: mime-types are only useful if\nunderstood by many parties. Therefore, the IANA assigns names which\ncan be used. In the table kept by this \"MIME::Types\" module all\nthese names, plus the most often used temporary names are kept. When\nnames seem to be missing, please contact the maintainer for\ninclusion.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "This module is part of MIME-Types distribution version 2.22, built on\nOctober 27, 2021. Website: http://perl.overmeer.net/CPAN/\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "Copyrights 1999-2021 by [Mark Overmeer <markov@cpan.org>]. For other\ncontributors see ChangeLog.\n\nThis program is free software; you can redistribute it and/or modify it\nunder the same terms as Perl itself. See http://dev.perl.org/licenses/\n",
            "subsections": []
        }
    },
    "summary": "MIME::Types - Definition of MIME types",
    "flags": [],
    "examples": [],
    "see_also": []
}