home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2000 May
/
Chip_2000-05_cd1.bin
/
zkuste
/
Perl
/
ActivePerl-5.6.0.613.msi
/
䆊䌷䈹䈙䏵-䞅䞆䞀㡆䞃䄦䠥
/
_22ab0b5e868f83d3d9a1f9c44c878639
< prev
next >
Wrap
Text File
|
2000-03-23
|
4KB
|
121 lines
<HTML>
<HEAD>
<TITLE>LWP::MediaTypes - guess media type for a file or a URL</TITLE>
<LINK REL="stylesheet" HREF="../../../Active.css" TYPE="text/css">
<LINK REV="made" HREF="mailto:">
</HEAD>
<BODY>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> LWP::MediaTypes - guess media type for a file or a URL</P></STRONG>
</TD></TR>
</TABLE>
<A NAME="__index__"></A>
<!-- INDEX BEGIN -->
<UL>
<LI><A HREF="#name">NAME</A></LI><LI><A HREF="#supportedplatforms">SUPPORTED PLATFORMS</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>
<H1><A NAME="name">NAME</A></H1>
<P>LWP::MediaTypes - guess media type for a file or a URL</P>
<P>
<HR>
<H1><A NAME="supportedplatforms">SUPPORTED PLATFORMS</A></H1>
<UL>
<LI>Linux</LI>
<LI>Solaris</LI>
<LI>Windows</LI>
</UL>
<HR>
<H1><A NAME="synopsis">SYNOPSIS</A></H1>
<PRE>
use LWP::MediaTypes qw(guess_media_type);
$type = guess_media_type("/tmp/foo.gif");</PRE>
<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 extentions 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 compatability 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_or_url, [$header_to_modify])</A></STRONG><BR>
<DD>
This function tries to guess media type and encoding for a file or url.
It returns the content-type, which is a string like <CODE>"text/html"</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>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 <CODE>-T</CODE> Perl operator take a look.
If this works (and <CODE>-T</CODE> 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>
<P>The optional second argument should be a reference to a HTTP::Headers
object or any object that implements the $obj->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>
<P></P>
<DT><STRONG><A NAME="item_media_suffix"><CODE>media_suffix($type,...)</CODE></A></STRONG><BR>
<DD>
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.
<P>Examples:</P>
<PRE>
@suffixes = media_suffix('image/*', 'audio/basic');
$suffix = media_suffix('text/html');</PRE>
<P></P></DL>
<P>The following functions are only exported by explict request:</P>
<DL>
<DT><STRONG><A NAME="item_add_type">add_type($type, @exts)</A></STRONG><BR>
<DD>
Associate a list of file extensions with the given media type.
<P>Example:</P>
<PRE>
add_type("x-world/x-vrml" => qw(wrl vrml));</PRE>
<P></P>
<DT><STRONG><A NAME="item_add_encoding">add_encoding($type, @ext)</A></STRONG><BR>
<DD>
Associate a list of file extensions with an encoding type.
<P>Example:</P>
<PRE>
add_encoding("x-gzip" => "gz");</PRE>
<P></P>
<DT><STRONG><A NAME="item_read_media_types"><CODE>read_media_types(@files)</CODE></A></STRONG><BR>
<DD>
Parse media types files and add the type mappings found there.
<P>Example:</P>
<PRE>
read_media_types("conf/mime.types");</PRE>
<P></P></DL>
<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>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>
<TR><TD CLASS=block VALIGN=MIDDLE WIDTH=100% BGCOLOR="#cccccc">
<STRONG><P CLASS=block> LWP::MediaTypes - guess media type for a file or a URL</P></STRONG>
</TD></TR>
</TABLE>
</BODY>
</HTML>