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.
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?
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?
<?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->file($filename);
?>