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. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.

You May Also Like…

Meraki Open Source Licenses

Until today I assumed that Meraki was built in-house with only closed source software. But having a look at the...


If you have Veeam backup failing with the Updating BCD failed with Cannot update SafeBoot flag and SentinelOne is...