PHP Classes

finfo: Determine the type of files analyzing its contents

Recommend this page to a friend!
  Info   View files View files (5)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2012-03-16 (4 years ago) RSS 2.0 feedNot yet rated by the usersTotal: 342 All time: 6,695 This week: 794Up
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
Name: Uku-Kaarel Jo~esaar <contact>
Classes: 8 packages by
Country: Estonia Estonia
Age: 33
All time rank: 4041 in Estonia Estonia
Week rank: 447 Down2 in Estonia Estonia Down
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:
  Files folder image Files  
File Role Description
Plain text file class.finfo.php Class methods to try guess file type
Accessible without login Plain text file example.multipleFiles.php Example Lists directory files and their mime types
Accessible without login Plain text file example.myMagicDef.php Example Shows how to add or replace magic pattern
Accessible without login Plain text file loader.finfo.php Aux. loads finfo class if needed
Accessible without login Plain text file readme.doc.txt Doc. About implementation specific features

 Version Control Unique User Downloads Download Rankings  
This week:0
All time:6,695
This week:794Up