{
    "mode": "perldoc",
    "parameter": "LWP::MediaTypes",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/LWP%3A%3AMediaTypes/json",
    "generated": "2026-06-12T14:46:47Z",
    "synopsis": "use LWP::MediaTypes qw(guessmediatype);\n$type = guessmediatype(\"/tmp/foo.gif\");",
    "sections": {
        "NAME": {
            "content": "LWP::MediaTypes - guess media type for a file or a URL\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use LWP::MediaTypes qw(guessmediatype);\n$type = guessmediatype(\"/tmp/foo.gif\");\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This module provides functions for handling media (also known as MIME) types and encodings. The\nmapping from file extensions to media types is defined by the media.types file. If the\n~/.media.types file exists it is used instead. For backwards compatibility we will also look for\n~/.mime.types.\n\nThe following functions are exported by default:\n",
            "subsections": [
                {
                    "name": "guess_media_type",
                    "content": ""
                },
                {
                    "name": "guess_media_type",
                    "content": ""
                },
                {
                    "name": "guess_media_type",
                    "content": "This function tries to guess media type and encoding for a file or objects that support the\na \"path\" or \"filename\" method, eg, URI or File::Temp objects. When an object does not\nsupport either method, it will be stringified to determine the filename. It returns the\ncontent type, which is a string like \"text/html\". In array context it also returns any\ncontent encodings applied (in the order used to encode the file). You can pass a URI object\nreference, instead of the file name.\n\nIf the type can not be deduced from looking at the file name, then guessmediatype() will\nlet the \"-T\" Perl operator take a look. If this works (and \"-T\" returns a TRUE value) then\nwe return *text/plain* as the type, otherwise we return *application/octet-stream* as the\ntype.\n\nThe optional second argument should be a reference to a HTTP::Headers object or any object\nthat implements the $obj->header method in a similar way. When it is present the values of\nthe 'Content-Type' and 'Content-Encoding' will be set for this header.\n"
                },
                {
                    "name": "media_suffix",
                    "content": "This function will return all suffixes that can be used to denote the specified media\ntype(s). Wildcard types can be used. In a scalar context it will return the first suffix\nfound. Examples:\n\n@suffixes = mediasuffix('image/*', 'audio/basic');\n$suffix = mediasuffix('text/html');\n\nThe following functions are only exported by explicit request:\n"
                },
                {
                    "name": "add_type",
                    "content": "Associate a list of file extensions with the given media type. Example:\n\naddtype(\"x-world/x-vrml\" => qw(wrl vrml));\n"
                },
                {
                    "name": "add_encoding",
                    "content": "Associate a list of file extensions with an encoding type. Example:\n\naddencoding(\"x-gzip\" => \"gz\");\n"
                },
                {
                    "name": "read_media_types",
                    "content": "Parse media types files and add the type mappings found there. Example:\n\nreadmediatypes(\"conf/mime.types\");\n"
                }
            ]
        },
        "COPYRIGHT": {
            "content": "Copyright 1995-1999 Gisle Aas.\n\nThis library is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n",
            "subsections": []
        }
    },
    "summary": "LWP::MediaTypes - guess media type for a file or a URL",
    "flags": [],
    "examples": [],
    "see_also": []
}