PHP FileInfo

Written by James McDonald

October 22, 2011

Trying to get PHP to return the file type of an xcf image and it stubbornly refused to return what I wanted.

Still can’t get it to output image/x-xcf but I’m starting to think the compiled in magic data base of PHP doesn’t include it and I haven’t successfully loaded a system magic.mgc file.

file -bi gimp_image.xcf
image/x-xcf; charset=binary

I have managed to get it to tell me it’s a GIMP Image using FILEINFO_CONTINUE or FILEINFO_NONE

< ?php
$file = 'gimp_image.xcf';
# $file = 'test.txt';

$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $file);

echo $mime . "\n";

$finfo = finfo_open(FILEINFO_CONTINUE);
$mime = finfo_file($finfo, $file);

echo $mime . "\n"; 
# output
GIMP XCF image data, version 0, 1078 x 718, RGB Color



Submit a Comment

Your email address will not be published.

You May Also Like…


Zebra Printer Language The above website has a page where you can enter ZPL and it...

PHP Iterators

Just came across a Youtube talk "Iterators in PHP" by Jake Smith published in 2014 that steps through the many...

PHP array_map Multiple Arrays

array_map can take multiple arrays. I like how it starts mapping through them starting at the first element of each...