简体   繁体   中英

PHP: Basic exiftool usage

I am trying to use exiftool (because it has all image tags vs. other tools) on a webserver. The perl module is installed in /bin/exiftool

The test.jpg is the same directory and has EXIF data.

<?php
#!/usr/bin/exiftool

$array = [];

eval(`$array=` . `exiftool -php -q test.jpg`);

print_r($array);
?>

The $array is empty though. I also tried:

eval(`$array=` . `exiftool -php -q test.jpg > output.txt`);

This creates an empty output.txt file.

I feel I have something very basic wrong but can't work it out. Like to add, I am on a shared host and have root/command line access.


No Update: I still struggle. I think it's related to cgi / perl (or my lack of knowledge about it)

As far as I know, exiftool is a Perl program and thus external code to PHP. I think eval is not probate to run external code. Try exec .

Datahardy.

You can use the exec() function for that:

$exifToolPath = 'cgi-bin/exiftool';
$exifToolParams = '-G';

// Read EXIF from jpg
$img = 'test.jpg';
exec($exifToolPath.' '.$exifToolParams.' '.$img, $data);
var_dump(array_unique($data));

// Read EXIF from NEF
$img = 'test.NEF';
exec($exifToolPath.' '.$exifToolParams.' '.$img, $data);

// Read XMP
$img = 'test.xmp';
exec($exifToolPath.' '.$exifToolParams.' '.$img, $data);
sort($data);
var_dump(array_unique($data));

You can also install exiftool with composer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM