I am trying to determine if some files are actually images (using PHP). I was advised to use finfo and I am trying to understand how this works.
What I am not getting is a database of magic numbers and how does it work? I'm a little puzzled - does each file have a specific βmagic numberβ that you are comparing with this database?
Also, I have this on my debian squeeze - but will it also be available on the WIN platform? or will you need to attach this database with the application?
<?php $finfo = new finfo(FILEINFO_MIME, "/usr/share/misc/magic.mgc"); if (!$finfo) { echo "Opening fileinfo database failed"; exit(); } $filename = "/usr/local/something.txt"; echo $finfo->file($filename); ?>
Stann source share