How to get the file type in PHP
<p>I have a <code>.doc</code> file and I renamed named it to give it a <code>.jpg</code> extension. When I process the renamed file with my function it accepts the file as having a <code>.jpg</code> although the file is not really a JPEG. What's the best way to find the actual file type? Here is my current code:</p>

<pre><code>function getExtension($str) {
   $i = strrpos($str,".");
   if (!$i) { return ""; }
   $l = strlen($str) - $i;
   $ext = substr($str,$i+1,$l);
   return $ext;
}
</code></pre>

<p>What's the best way to check the file's type without depending on the extension?</p>
