1

Is there any way to check that a files mime-type matches it's extension in php ?

Thanks, Adam

adam
  • 11
  • 2

2 Answers2

0

See here: http://www.php.net/manual/en/function.finfo-file.php. This function allows you to detect the file's mime-type.

  • I know how to get a files mime type as well as it's extension. What that page does not explain is how to check if a files mime-type matches it's extension. – adam Sep 09 '11 at 17:34
  • Check this out: http://stackoverflow.com/questions/1147931/how-do-i-determine-the-extensions-associated-with-a-mime-type-in-php – Joel A. Villarreal Bertoldi Sep 09 '11 at 17:34
0

If you have a list of known mime types with corresponding extensions, using the mime_content_type function and looking up the extension in an array is simple. There are problems, however; a comprehensive list would be large and likely become outdated fairly quickly, and sniffing mime types is generally considered a difficult problem with inaccurate solutions.

You
  • 22,800
  • 3
  • 51
  • 64