Chapter 4. Supporting MIME types
Content analysis
The first is to look in the file’s content and deduce the MIME content type from the
content.
You can see this mechanism in action with the file command. This command can give
a “human readable” description of a file’s content type or, with the -i option, it can
give a MIME content type.
$ file course.pdf
course.pdf: PDF document, version 1.2
$ file course.ps
course.ps: PostScript document text conforming at level 2.0
$ file -i course.ps
file: Using regular magic file ‘/usr/share/magic.mime’
course.ps: application/postscript
$ file -i course.ps 2> /dev/null
course.ps: application/postscript
$ file -i course.pdf 2> /dev/null
course.pdf: application/pdf
Figure 4-3. Using the file command
As you will deduce from the warning message printed on standard error, the file
/usr/share/magic.mime is used to store the information about how to map from
content to MIME type. The default file /usr/share/magic is used for the more ver-
bose descriptions.
File name analysis
The other approach is to use the file name. In particular it is traditional that files
should have particular suffices according to their MIME content types. This is the
most commonly used approach.
This approach is taken by other utilities than just the web server and there is a system
wide file giving the correspondence between file names and MIME content types.
This file is /etc/mime.types which is part of the base system (as part of the mailcap
package).
application/msword doc
application/pdf pdf
application/postscript ai eps ps
application/rtf rtf
application/x-bzip2 bz2
application/x-dvi dvi
application/xml
audio/mpeg mpga mp2 mp3
image/png png
model/vrml wrl vrml
text/html html htm
text/plain asc txt
video/mpeg mpeg mpg mpe
video/quicktime qt mov
Figure 4-4. Extracts from /etc/mime.types
Apache is capable of both modes of operation. We will use the latter as it is more
common. This is for historical reasons and is not a reflection on the relative values of
the two mechanisms.
24
Comentarios a estos manuales