1<?xml version="1.0" encoding="ISO-8859-1"?> 2<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 3<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><!-- 4 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 5 This file is generated from xml source: DO NOT EDIT 6 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 7 --> 8<title>mod_mime_magic - Apache HTTP Server</title> 9<link href="/style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" /> 10<link href="/style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" /> 11<link href="/style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="/style/css/prettify.css" /> 12<script src="/style/scripts/prettify.min.js" type="text/javascript"> 13</script> 14 15<link href="/images/favicon.ico" rel="shortcut icon" /></head> 16<body> 17<div id="page-header"> 18<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p> 19<p class="apache">Apache HTTP Server Version 2.4</p> 20<img alt="" src="/images/feather.gif" /></div> 21<div class="up"><a href="./"><img title="<-" alt="<-" src="/images/left.gif" /></a></div> 22<div id="path"> 23<a href="http://www.apache.org/">Apache</a> > <a href="http://httpd.apache.org/">HTTP Server</a> > <a href="http://httpd.apache.org/docs/">Documentation</a> > <a href="../">Version 2.4</a> > <a href="./">Modules</a></div> 24<div id="page-content"> 25<div id="preamble"><h1>Apache Module mod_mime_magic</h1> 26<div class="toplang"> 27<p><span>Available Languages: </span><a href="/en/mod/mod_mime_magic.html" title="English"> en </a> | 28<a href="/fr/mod/mod_mime_magic.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a></p> 29</div> 30<table class="module"><tr><th><a href="module-dict.html#Description">Description:</a></th><td>Determines the MIME type of a file 31 by looking at a few bytes of its contents</td></tr> 32<tr><th><a href="module-dict.html#Status">Status:</a></th><td>Extension</td></tr> 33<tr><th><a href="module-dict.html#ModuleIdentifier">Module�Identifier:</a></th><td>mime_magic_module</td></tr> 34<tr><th><a href="module-dict.html#SourceFile">Source�File:</a></th><td>mod_mime_magic.c</td></tr></table> 35<h3>Summary</h3> 36 37 <p>This module determines the <a class="glossarylink" href="/glossary.html#mime-type" title="see glossary">MIME 38 type</a> of files in the same way the Unix 39 <code>file(1)</code> command works: it looks at the first few 40 bytes of the file. It is intended as a "second line of defense" 41 for cases that <code class="module"><a href="/mod/mod_mime.html">mod_mime</a></code> can't resolve.</p> 42 43 <p>This module is derived from a free version of the 44 <code>file(1)</code> command for Unix, which uses "magic 45 numbers" and other hints from a file's contents to figure out 46 what the contents are. This module is active only if the magic 47 file is specified by the <code class="directive"><a href="#mimemagicfile">MimeMagicFile</a></code> directive.</p> 48</div> 49<div id="quickview"><h3 class="directives">Directives</h3> 50<ul id="toc"> 51<li><img alt="" src="/images/down.gif" /> <a href="#mimemagicfile">MimeMagicFile</a></li> 52</ul> 53<h3>Topics</h3> 54<ul id="topics"> 55<li><img alt="" src="/images/down.gif" /> <a href="#format">Format of the Magic File</a></li> 56<li><img alt="" src="/images/down.gif" /> <a href="#performance">Performance Issues</a></li> 57<li><img alt="" src="/images/down.gif" /> <a href="#notes">Notes</a></li> 58</ul><ul class="seealso"><li><a href="#comments_section">Comments</a></li></ul></div> 59<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 60<div class="section"> 61<h2><a name="format" id="format">Format of the Magic File</a></h2> 62 63 <p>The contents of the file are plain ASCII text in 4-5 64 columns. Blank lines are allowed but ignored. Commented lines 65 use a hash mark (<code>#</code>). The remaining lines are parsed for 66 the following columns:</p> 67 68 <table class="bordered"><tr class="header"><th>Column</th><th>Description</th></tr> 69<tr><td>1</td> 70 <td>byte number to begin checking from<br /> 71 "<code>></code>" indicates a dependency upon the previous 72 non-"<code>></code>" line</td></tr> 73<tr class="odd"><td>2</td> 74 <td><p>type of data to match</p> 75 <table class="bordered"> 76 77 <tr><td><code>byte</code></td> 78 <td>single character</td></tr> 79 <tr><td><code>short</code></td> 80 <td>machine-order 16-bit integer</td></tr> 81 <tr><td><code>long</code></td> 82 <td>machine-order 32-bit integer</td></tr> 83 <tr><td><code>string</code></td> 84 <td>arbitrary-length string</td></tr> 85 <tr><td><code>date</code></td> 86 <td>long integer date (seconds since Unix epoch/1970)</td></tr> 87 <tr><td><code>beshort</code></td> 88 <td>big-endian 16-bit integer</td></tr> 89 <tr><td><code>belong</code></td> 90 <td>big-endian 32-bit integer</td></tr> 91 <tr><td><code>bedate</code></td> 92 <td>big-endian 32-bit integer date</td></tr> 93 <tr><td><code>leshort</code></td> 94 <td>little-endian 16-bit integer</td></tr> 95 <tr><td><code>lelong</code></td> 96 <td>little-endian 32-bit integer</td></tr> 97 <tr><td><code>ledate</code></td> 98 <td>little-endian 32-bit integer date</td></tr> 99 </table></td></tr> 100<tr><td>3</td> 101 <td>contents of data to match</td></tr> 102<tr class="odd"><td>4</td> 103 <td>MIME type if matched</td></tr> 104<tr><td>5</td> 105 <td>MIME encoding if matched (optional)</td></tr> 106</table> 107 108 <p>For example, the following magic file lines would recognize 109 some audio formats:</p> 110 111 <div class="example"><pre># Sun/NeXT audio data 1120 string .snd 113>12 belong 1 audio/basic 114>12 belong 2 audio/basic 115>12 belong 3 audio/basic 116>12 belong 4 audio/basic 117>12 belong 5 audio/basic 118>12 belong 6 audio/basic 119>12 belong 7 audio/basic 120>12 belong 23 audio/x-adpcm</pre></div> 121 122 <p>Or these would recognize the difference between <code>*.doc</code> 123 files containing Microsoft Word or FrameMaker documents. (These are 124 incompatible file formats which use the same file suffix.)</p> 125 126 <div class="example"><pre># Frame 1270 string \<MakerFile application/x-frame 1280 string \<MIFFile application/x-frame 1290 string \<MakerDictionary application/x-frame 1300 string \<MakerScreenFon application/x-frame 1310 string \<MML application/x-frame 1320 string \<Book application/x-frame 1330 string \<Maker application/x-frame 134 135# MS-Word 1360 string \376\067\0\043 application/msword 1370 string \320\317\021\340\241\261 application/msword 1380 string \333\245-\0\0\0 application/msword</pre></div> 139 140 <p>An optional MIME encoding can be included as a fifth column. 141 For example, this can recognize gzipped files and set the 142 encoding for them.</p> 143 144 <div class="example"><pre># gzip (GNU zip, not to be confused with 145# [Info-ZIP/PKWARE] zip archiver) 146 1470 string \037\213 application/octet-stream x-gzip</pre></div> 148</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 149<div class="section"> 150<h2><a name="performance" id="performance">Performance Issues</a></h2> 151 <p>This module is not for every system. If your system is barely 152 keeping up with its load or if you're performing a web server 153 benchmark, you may not want to enable this because the 154 processing is not free.</p> 155 156 <p>However, an effort was made to improve the performance of 157 the original <code>file(1)</code> code to make it fit in a busy web 158 server. It was designed for a server where there are thousands of users 159 who publish their own documents. This is probably very common 160 on intranets. Many times, it's helpful if the server can make 161 more intelligent decisions about a file's contents than the 162 file name allows ...even if just to reduce the "why doesn't my 163 page work" calls when users improperly name their own files. 164 You have to decide if the extra work suits your 165 environment.</p> 166</div><div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 167<div class="section"> 168<h2><a name="notes" id="notes">Notes</a></h2> 169 <p>The following notes apply to the <code class="module"><a href="/mod/mod_mime_magic.html">mod_mime_magic</a></code> 170 module and are included here for compliance with contributors' 171 copyright restrictions that require their acknowledgment.</p> 172 173 <div class="note"> 174 <p>mod_mime_magic: MIME type lookup via file magic numbers<br /> 175 Copyright (c) 1996-1997 Cisco Systems, Inc.</p> 176 177 <p>This software was submitted by Cisco Systems to the Apache Group 178 in July 1997. Future revisions and derivatives of this source code 179 must acknowledge Cisco Systems as the original contributor of this 180 module. All other licensing and usage conditions are those of the 181 Apache Group.</p> 182 183 <p>Some of this code is derived from the free version of the file 184 command originally posted to comp.sources.unix. Copyright info for 185 that program is included below as required.</p> 186 </div> 187 188 <div class="note"> 189 <p> - Copyright (c) Ian F. Darwin, 1987. Written by Ian F. Darwin.</p> 190 191 <p>This software is not subject to any license of the American 192 Telephone and Telegraph Company or of the Regents of the University 193 of California.</p> 194 195 <p>Permission is granted to anyone to use this software for any 196 purpose on any computer system, and to alter it and redistribute it 197 freely, subject to the following restrictions:</p> 198 199 <ol> 200 <li>The author is not responsible for the consequences of use of 201 this software, no matter how awful, even if they arise from flaws 202 in it.</li> 203 204 <li>The origin of this software must not be misrepresented, either 205 by explicit claim or by omission. Since few users ever read 206 sources, credits must appear in the documentation.</li> 207 208 <li>Altered versions must be plainly marked as such, and must not 209 be misrepresented as being the original software. Since few users 210 ever read sources, credits must appear in the documentation.</li> 211 212 <li>This notice may not be removed or altered.</li> 213 </ol> 214 </div> 215 216 <div class="note"> 217 <p>For compliance with Mr Darwin's terms: this has been very 218 significantly modified from the free "file" command.</p> 219 220 <ul> 221 <li>all-in-one file for compilation convenience when moving from 222 one version of Apache to the next.</li> 223 224 <li>Memory allocation is done through the Apache API's pool 225 structure.</li> 226 227 <li>All functions have had necessary Apache API request or server 228 structures passed to them where necessary to call other Apache API 229 routines. (<em>i.e.</em>, usually for logging, files, or memory 230 allocation in itself or a called function.)</li> 231 232 <li>struct magic has been converted from an array to a single-ended 233 linked list because it only grows one record at a time, it's only 234 accessed sequentially, and the Apache API has no equivalent of 235 <code>realloc()</code>.</li> 236 237 <li>Functions have been changed to get their parameters from the 238 server configuration instead of globals. (It should be reentrant 239 now but has not been tested in a threaded environment.)</li> 240 241 <li>Places where it used to print results to stdout now saves them 242 in a list where they're used to set the MIME type in the Apache 243 request record.</li> 244 245 <li>Command-line flags have been removed since they will never be 246 used here.</li> 247 </ul> 248 </div> 249</div> 250<div class="top"><a href="#page-header"><img alt="top" src="/images/up.gif" /></a></div> 251<div class="directive-section"><h2><a name="MimeMagicFile" id="MimeMagicFile">MimeMagicFile</a> <a name="mimemagicfile" id="mimemagicfile">Directive</a></h2> 252<table class="directive"> 253<tr><th><a href="directive-dict.html#Description">Description:</a></th><td>Enable MIME-type determination based on file contents 254using the specified magic file</td></tr> 255<tr><th><a href="directive-dict.html#Syntax">Syntax:</a></th><td><code>MimeMagicFile <var>file-path</var></code></td></tr> 256<tr><th><a href="directive-dict.html#Context">Context:</a></th><td>server config, virtual host</td></tr> 257<tr><th><a href="directive-dict.html#Status">Status:</a></th><td>Extension</td></tr> 258<tr><th><a href="directive-dict.html#Module">Module:</a></th><td>mod_mime_magic</td></tr> 259</table> 260 <p>The <code class="directive">MimeMagicFile</code> directive can be used to 261 enable this module, the default file is distributed at 262 <code>conf/magic</code>. Non-rooted paths are relative to the 263 <code class="directive"><a href="/mod/core.html#serverroot">ServerRoot</a></code>. Virtual hosts will use 264 the same file as the main server unless a more specific setting is 265 used, in which case the more specific setting overrides the main 266 server's file.</p> 267 268 <div class="example"><h3>Example</h3><pre class="prettyprint lang-config">MimeMagicFile conf/magic</pre> 269</div> 270 271</div> 272</div> 273<div class="bottomlang"> 274<p><span>Available Languages: </span><a href="/en/mod/mod_mime_magic.html" title="English"> en </a> | 275<a href="/fr/mod/mod_mime_magic.html" hreflang="fr" rel="alternate" title="Fran�ais"> fr </a></p> 276</div><div class="top"><a href="#page-header"><img src="/images/up.gif" alt="top" /></a></div><div class="section"><h2><a id="comments_section" name="comments_section">Comments</a></h2><div class="warning"><strong>Notice:</strong><br />This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our <a href="http://httpd.apache.org/lists.html">mailing lists</a>.</div> 277<script type="text/javascript"><!--//--><![CDATA[//><!-- 278var comments_shortname = 'httpd'; 279var comments_identifier = 'http://httpd.apache.org/docs/2.4/mod/mod_mime_magic.html'; 280(function(w, d) { 281 if (w.location.hostname.toLowerCase() == "httpd.apache.org") { 282 d.write('<div id="comments_thread"><\/div>'); 283 var s = d.createElement('script'); 284 s.type = 'text/javascript'; 285 s.async = true; 286 s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier; 287 (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s); 288 } 289 else { 290 d.write('<div id="comments_thread">Comments are disabled for this page at the moment.<\/div>'); 291 } 292})(window, document); 293//--><!]]></script></div><div id="footer"> 294<p class="apache">Copyright 2014 The Apache Software Foundation.<br />Licensed under the <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache License, Version 2.0</a>.</p> 295<p class="menu"><a href="/mod/">Modules</a> | <a href="/mod/directives.html">Directives</a> | <a href="http://wiki.apache.org/httpd/FAQ">FAQ</a> | <a href="/glossary.html">Glossary</a> | <a href="/sitemap.html">Sitemap</a></p></div><script type="text/javascript"><!--//--><![CDATA[//><!-- 296if (typeof(prettyPrint) !== 'undefined') { 297 prettyPrint(); 298} 299//--><!]]></script> 300</body></html>