finfo: Determine the type of files analyzing its contents

Recommend this page to a friend!
  Info   Example   View files (17)   Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 346 All time: 6,910 This week: 410
Version License PHP version Categories
finfo 1.0GNU General Publi...5PHP 5, Files and Folders
Description Author

This class can determine the type of files analyzing its contents.

It provides an interface compatible with PHP finfo extension under systems that do not have that PHP extension available.

It takes the path of a file and uses the file command to analyze its contents when possible. Otherwise the class reads the file contents to guess the file type and character encoding.

Innovation Award
PHP Programming Innovation award nominee
March 2012
Number 6

Prize: One downloadable e-book of choice by O'Reilly
finfo is an useful PHP extension that makes it possible to determine the type of data contained in files by examining its contents.

Unfortunately the finfo extension is not available in all PHP setups. This class provides a work around by emulating the functionality of the finfo extensionin pure PHP code.

Manuel Lemos
Picture of Uku-Kaarel Jo~esaar
Name: Uku-Kaarel Jo~esaar <contact>
Classes: 8 packages by
Country: Estonia Estonia
Age: 37
All time rank: 3931 in Estonia Estonia
Week rank: 61 2 in Estonia Estonia
Innovation award
Innovation award
Nominee: 5x


 public $no_magic    <-- built in magic 
 public $flags       <-- finfo flags
 public $magic_file  <-- path to magic file
    Extra methods are not implmented in php's own 'finfo'

    Set or overwrite/override magic file description
    set_magicDescription($key, $array);
    Returns true if mime class is "text", also returns true on XML, CSS, JS, RTF, PHP.
 About me:
File Role Description
dir (11 files)
class.finfo.php Class methods to try guess file type
example.multipleFiles.php Example Lists directory files and their mime types
example.myMagicDef.php Aux. Shows how to add or replace magic pattern
loader.finfo.php Aux. loads finfo class if needed
readme.doc.txt Doc. About implementation specific features Doc. Documentation

  Files  /  dir  
File Role Description
   A4_to_A5.png Data Auxiliary data
   birds.rtf Data Auxiliary data
   favicon.ico Data Auxiliary data
   google_browser_detection.js Data Auxiliary data
   HEADER Data Auxiliary data
   index.html Doc. Documentation
   jquery.qtip.min.css Data Auxiliary data
   sunset.jpg Icon Icon image
   test.csv Data Auxiliary data
   tree_expand.gif Icon Icon image
   webgps.c.txt Doc. Documentation

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:6,910
This week:410

For more information send a message to info at phpclasses dot org.