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.

e.g.
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";
#output
application/octet-stream

$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

?>



0 Comments

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…

Network speed test host to host

On Ubuntu / Debian apt-get install iperf3 On Windows download it from https://iperf.fr/iperf-download.php#windows Make...

Clear HSTS Settings in CHrome

Open chrome://net-internals/#hsts enter the domain in the query field and click Query to confirm it has HSTS settings...