<p>I have an <em>index.php</em> file which has to process many different file types. How do I guess the filetype based on the <code>REQUEST_URI</code>?</p>
<p>If I request <code>http://site/image.jpg</code>, and all requests redirect through <em>index.php</em>, which looks like this</p>
<pre><code>&lt;?php
   include('/www/site'.$_SERVER['REQUEST_URI']);
?&gt;
</code></pre>
<p>How would I make that work correctly?</p>
<p>Should I test based on the extension of the file requested, or is there a way to get the filetype?</p>

If you are sure you're only ever working with images, you can check out the
exif_imagetype()
PHP function, which attempts to return the image MIME type.
If you don't mind external dependencies, you can also check out the excellent
getID3
library which can determine the MIME type of many different file types.
Lastly, you can check out the
mime_content_type()
function - but it has been deprecated for the
Fileinfo
PECL extension.