Best way to recognize a filetype in php

LuRsT picture LuRsT · Jan 19, 2009 · Viewed 8.6k times · Source

What's the best way to discover a file's filetype within php? I heard that the browser may be tricked, so what's a better way of doing this?

Answer

Carlo picture Carlo · Jan 19, 2009

You can use finfo_file

<?php
echo finfo_file(finfo_open(FILEINFO_MIME), "foo.png");
?>