{
    "mode": "perldoc",
    "parameter": "MIME::Types",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/MIME%3A%3ATypes/json",
    "generated": "2026-06-10T01:07:11Z",
    "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 and HTTP traffic) to\nindicate the type of content which is transmitted. or expected. See RFC2045 at\nhttps://www.ietf.org/rfc/rfc2045.txt\n\nSometimes detailed knowledge about a mime-type is need, however this module only knows about the\nfile-name extensions which relate to some filetype. It can also be used to produce the right\nformat: types which are not registered at IANA need to use 'x-' prefixes.\n\nThis object administers a huge list of known mime-types, combined from various sources. For\ninstance, it contains all IANA types and the knowledge of Apache. Probably the most complete\ntable on the net!\n\nMIME::Types and daemons (fork)\nIf your program uses fork (usually for a daemon), then you want to have the type table\ninitialized 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 the object you create\nhere) you will get access to the same global table of 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 current implementation, it\ndoes not matter whether you create this object often within your program, but in the future\nthis 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. Only the first\ninstantiation of this object will have this parameter obeyed.\n\n[2.10] This parameter can be globally overruled via the \"PERLMIMETYPEDB\" environment\nvariable, which may be needed in case of PAR or other tricky installations. For PAR, you\nprobably set this environment variable to \"inc/lib/MIME/types.db\"\n\nonlycomplete => BOOLEAN\nOnly include complete MIME type definitions: requires at least one known extension. This\nwill reduce the number of entries --and with that the amount of memory consumed--\nconsiderably.\n\nIn your program you have to decide: the first time that you call the creator (\"new\")\ndetermines whether you get the full or the partial 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 large.\n"
                },
                {
                    "name": "Knowledge",
                    "content": "$obj->addType($type, ...)\nAdd one or more TYPEs to the set of known types. Each TYPE is a \"MIME::Type\" which must be\nexperimental: either the main-type or the sub-type must start with \"x-\".\n\nPlease inform the maintainer of this module when registered types are missing. Before\nversion MIME::Types version 1.14, a warning was produced when an unknown IANA type was\nadded. This has been removed, because 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 instantiate MIME::Type\nobjects. See types()\n\n$obj->mimeTypeOf($filename)\nReturns the \"MIME::Type\" object which belongs to the FILENAME (or simply its filename\nextension) or \"undef\" if the file type is unknown. The extension is used and considered\ncase-insensitive.\n\nIn some cases, more than one type is known for a certain filename extension. In that case,\nthe preferred one is taken (for an unclear definition 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. [2.00] Only one type\nwill be returned.\n\n[before 2.00] One type may be described more than once. Different extensions may be in use\nfor this type, and different operating systems may cause more than one \"MIME::Type\" object\nto be defined. In scalar context, only the first is returned.\n\n$obj->types()\nReturns a list of all defined mime-types. For reasons of backwards compatibility, this will\ninstantiate MIME::Type objects, which will be returned. See listTypes().\n\nHTTP support\n$obj->httpAccept($header)\n[2.07] Decompose a typical HTTP-Accept header, and sort it based on the included priority\ninformation. Returned is a sorted list of type names, where the highest priority type is\nfirst. The list may contain '*/*' (accept any) or a '*' as subtype.\n\nIll-formated typenames are ignored. On equal qualities, the order is kept. See RFC2616\nsection 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 types on preference.\nYou may also provide a list of ordered @types which may have been the result of that method,\ncalled earlier.\n\nAs second parameter, you pass a LIST of types you @have to offer. Those need to be\nMIME::Type objects. The preferred type will get selected. When none of these are accepted by\nthe client, this will return \"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 mime-type and filename,\nnot just the type. If $accept is \"undef\", the 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 MIME::Types versions [0.06] and\nbelow. This code originates from Jeff Okamoto okamoto@corp.hp.com and others.\n",
            "subsections": [
                {
                    "name": "by_mediatype",
                    "content": "This function takes a media type and returns a list or anonymous array of anonymous\nthree-element arrays whose values are the file name suffix used to identify it, the media\ntype, and a content encoding.\n\nTYPE can be a full type name (contains '/', and will be matched in full), a partial type\n(which is used as regular expression) or a real regular expression.\n"
                },
                {
                    "name": "by_suffix",
                    "content": "Like \"mimeTypeOf\", but does not return an \"MIME::Type\" object. If the file +type is unknown,\nboth the returned media type and encoding are 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"
                },
                {
                    "name": "import_mime_types",
                    "content": "This method has been removed: mime-types are only useful if understood by many parties.\nTherefore, the IANA assigns names which can be used. In the table kept by this \"MIME::Types\"\nmodule all these names, plus the most often used temporary names are kept. When names seem\nto be missing, please contact the maintainer for inclusion.\n"
                }
            ]
        },
        "SEE ALSO": {
            "content": "This module is part of MIME-Types distribution version 2.22, built on October 27, 2021. Website:\nhttp://perl.overmeer.net/CPAN/\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "Copyrights 1999-2021 by [Mark Overmeer <markov@cpan.org>]. For other contributors see ChangeLog.\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself. See http://dev.perl.org/licenses/\n",
            "subsections": []
        }
    },
    "summary": "MIME::Types - Definition of MIME types",
    "flags": [],
    "examples": [],
    "see_also": []
}