title: Determining Filetype with PHP. What is Magic Database?
body: <p>I'm trying to determine if some files are actually images (using PHP).
  I've been advised to use finfo and i'm trying to understand how it works.</p>
  
  <p>What I don't get is - what is a magic numbers database and how does it work? I'm a bit puzzled - does each file have certain "magic number" that you compare against that database? </p>
  
  <p>Also - I have it on my debian squeeze - but will it also be available on WIN platform? or would one have to attach that database along with the app?</p>
  
  <pre><code>&lt;?php
  $finfo = new finfo(FILEINFO_MIME, "/usr/share/misc/magic.mgc");
  if (!$finfo) {
      echo "Opening fileinfo database failed";
      exit();
  }
  
  /* get mime-type for a specific file */
  $filename = "/usr/local/something.txt";
  echo $finfo-&gt;file($filename);
  
  ?&gt;
  </code></pre>