PHP: Fileinfo Functions - Manual

downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

finfo_buffer fdf_set_version

Last updated: Fri, 26 Jan 2007

view this page in

# XXXVIII. Fileinfo Functions

# Введение

The functions in this module try to guess the content type and encoding of a file by looking for certain magic byte sequences at specific positions within the file. While this is not a bullet proof approach the heuristics used do a very good job.

# Требования

`magic_open` library is needed to build this extension.

# Установка

A short installation note: just type

    $ pear install fileinfo

in your console.

# Настройка во время выполнения

Данное расширение не определяет никакие директивы конфигурации в `php.ini`.

# Типы ресурсов

There is one resource used in Fileinfo extension: a magic database descriptor returned by finfo_open().

# Предопределенные константы

Перечисленные ниже константы определены данным расширением и могут быть доступны только в том случае, если PHP был собран с поддержкой этого расширения или же в том случае, если данное расширение подгружается во время выполнения.

`FILEINFO_NONE` (integer)

  No special handling.

`FILEINFO_SYMLINK` (integer)

  Follow symlinks.

`FILEINFO_MIME` (integer)

  Return a mime string, instead of a textual description.

`FILEINFO_COMPRESS` (integer)

  Decompress compressed files.

`FILEINFO_DEVICES` (integer)

  Look at the contents of blocks or character special devices.

`FILEINFO_CONTINUE` (integer)

  Return all matches, not just the first.

`FILEINFO_PRESERVE_ATIME` (integer)

  If possible preserve the original access time.

`FILEINFO_RAW` (integer)

  Don't translate unprintable characters to a `\ooo` octal representation.

add a note User Contributed Notes
Fileinfo Functions
Alexey
18-Feb-2007 06:39
`Well, it is hard to install and use this extension. There is better alternative - use lunux comand "file". For insturctions - "man file" from linux shell.
<?
echo system("file -i -b file.pdf");
?>
application/pdf`
szotsaki at gmail dot com
01-Feb-2007 11:12
`I am about to write how installed this package.
First of all, I tried with "pear install fileinfo" - as the manual says.
But the pear command said that 'Package "Fileinfo" is not valid,
install failed'.
Then the "pear install pecl/fileinfo" was a better way. But at that time the "phpize" command was missing.
I installed that (on openSUSE distributions it is in the php5-devel, but I think you can find it in your distro's corresponding php-devel package).
After that you may install "re2c" (I did). It's homepage is: http://sourceforge.net/projects/re2c
Copy the magic file of Apache (usually in /etc/apache2) into the following directory: /usr/locale/share/file/ or /usr/share/file/
Then you have to install "libmagic-dev". If you have Debian based system you can simply install it with apt.
But if you have an rpm based system (like me), you have to download the following package: http://packages.debian.org/unstable/libdevel/libmagic-dev
It contains the files we need.
So, download the file, browse it with Midnight Commander (mc) (you have to apt and dpkg be installed) and simply extract (so copy) the /usr folder (it is inside the CONTENTS folder) of the .deb package to the root folder.
And now give the "pear install pecl/fileinfo" command another try :)
Ps: Don't forget to check whether the script has wrote the following line into the php.ini (on openSUSE: /etc/php5/apache2): extension=fileinfo.so
I hope, I could help.`
motin at demomusic dot nu
09-Jan-2007 05:34
`I had a real headache trying to install this package through pear/pecl. Ran into what looks like this bug: http://pecl.php.net/bugs/bug.php?id=7673 (phpize fails)
I found downloading the package manually and running ./configure helped show what the problem is:
...
checking for fileinfo support... yes, shared
checking for magic files in default path... not found
configure: error: Please reinstall the libmagic distribution
<quit>
I though this was because of a missing magic-database like magic.mime but examining the configure-script, magic.h is searched for.
Problem for me was that include/magic.h was not found. After some googling about where to find magic.h led me to the dead
simple solution:
apt-get install libmagic-dev
This does NOT solve the original installation bug strangely enough, but allows for manual installation:
1. Find the url to the latest version of fileinfo from http://pecl.php.net/package/Fileinfo (atm: http://pecl.php.net/get/Fileinfo-1.0.4.tgz)
2. Download, compile and install
wget http://pecl.php.net/get/Fileinfo-1.0.4.tgz
gunzip Fileinfo-1.0.4.tgz
tar -xvf Fileinfo-1.0.4.tar
cd fileinfo-1.0.4
./configure
make
make install
3. Add extension=fileinfo.so in your php.ini file
4. Restart Apache`
jausions at php dot net
08-Jul-2006 12:26
`For Windows users:
1. Go to http://pecl4win.php.net/ to get the php_fileinfo.dll if your PHP installation didn't come with it, and you haven't installed the Extensions package.
2. Then make sure you have extension=php_fileinfo.dll somewhere in your php.ini
3. Restart your web server.`
deanariel at gmail dot com
13-Apr-2006 11:16
`Sometime "pear install fileinfo" won't work....
so you can try "pear install pecl/fileinfo"`
add a note
finfo_buffer fdf_set_version

Last updated: Fri, 26 Jan 2007
show source | credits | stats | sitemap | contact | advertising | mirror sites
Copyright © 2001-2007 The PHP Group
All rights reserved.
This mirror generously provided by: Yahoo! Inc.
Last updated: Sat Mar 10 10:36:09 2007 PST