mediatypes.html

来自「perl教程」· HTML 代码 · 共 149 行

HTML
149
字号
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>LWP::MediaTypes - guess media type for a file or a URL</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',2);</script>
<h1><a>LWP::MediaTypes - guess media type for a file or a URL</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#copyright">COPYRIGHT</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>LWP::MediaTypes - guess media type for a file or a URL</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
 <span class="keyword">use</span> <span class="variable">LWP::MediaTypes</span> <span class="string">qw(guess_media_type)</span><span class="operator">;</span>
 <span class="variable">$type</span> <span class="operator">=</span> <span class="variable">guess_media_type</span><span class="operator">(</span><span class="string">"/tmp/foo.gif"</span><span class="operator">);</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This module provides functions for handling media (also known as
MIME) types and encodings.  The mapping from file extensions to media
types is defined by the <em>media.types</em> file.  If the <em>~/.media.types</em>
file exists it is used instead.
For backwards compatibility we will also look for <em>~/.mime.types</em>.</p>
<p>The following functions are exported by default:</p>
<dl>
<dt><strong><a name="item_guess_media_type">guess_media_type( $filename )</a></strong>

<dt><strong>guess_media_type( $uri )</strong>

<dt><strong>guess_media_type( $filename_or_uri, $header_to_modify )</strong>

<dd>
<p>This function tries to guess media type and encoding for a file or a URI.
It returns the content type, which is a string like <code>&quot;text/html&quot;</code>.
In array context it also returns any content encodings applied (in the
order used to encode the file).  You can pass a URI object
reference, instead of the file name.</p>
</dd>
<dd>
<p>If the type can not be deduced from looking at the file name,
then <a href="#item_guess_media_type"><code>guess_media_type()</code></a> will let the <a href="../../lib/Pod/perlrun.html#item__2dt"><code>-T</code></a> Perl operator take a look.
If this works (and <a href="../../lib/Pod/perlrun.html#item__2dt"><code>-T</code></a> returns a TRUE value) then we return
<em>text/plain</em> as the type, otherwise we return
<em>application/octet-stream</em> as the type.</p>
</dd>
<dd>
<p>The optional second argument should be a reference to a HTTP::Headers
object or any object that implements the $obj-&gt;header method in a
similar way.  When it is present the values of the
'Content-Type' and 'Content-Encoding' will be set for this header.</p>
</dd>
</li>
<dt><strong><a name="item_media_suffix">media_suffix( $type, ... )</a></strong>

<dd>
<p>This function will return all suffixes that can be used to denote the
specified media type(s).  Wildcard types can be used.  In a scalar
context it will return the first suffix found. Examples:</p>
</dd>
<dd>
<pre>
  <span class="variable">@suffixes</span> <span class="operator">=</span> <span class="variable">media_suffix</span><span class="operator">(</span><span class="string">'image/*'</span><span class="operator">,</span> <span class="string">'audio/basic'</span><span class="operator">);</span>
  <span class="variable">$suffix</span> <span class="operator">=</span> <span class="variable">media_suffix</span><span class="operator">(</span><span class="string">'text/html'</span><span class="operator">);</span>
</pre>
</dd>
</li>
</dl>
<p>The following functions are only exported by explicit request:</p>
<dl>
<dt><strong><a name="item_add_type">add_type( $type, @exts )</a></strong>

<dd>
<p>Associate a list of file extensions with the given media type.
Example:</p>
</dd>
<dd>
<pre>
    <span class="variable">add_type</span><span class="operator">(</span><span class="string">"x-world/x-vrml"</span> <span class="operator">=&gt;</span> <span class="string">qw(wrl vrml)</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_add_encoding">add_encoding( $type, @ext )</a></strong>

<dd>
<p>Associate a list of file extensions with an encoding type.
Example:</p>
</dd>
<dd>
<pre>
 <span class="variable">add_encoding</span><span class="operator">(</span><span class="string">"x-gzip"</span> <span class="operator">=&gt;</span> <span class="string">"gz"</span><span class="operator">);</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_read_media_types">read_media_types( @files )</a></strong>

<dd>
<p>Parse media types files and add the type mappings found there.
Example:</p>
</dd>
<dd>
<pre>
    <span class="variable">read_media_types</span><span class="operator">(</span><span class="string">"conf/mime.types"</span><span class="operator">);</span>
</pre>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright 1995-1999 Gisle Aas.</p>
<p>This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.</p>

</body>

</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?