Curious problem using exiftool with php

Started by lifeofdave, April 26, 2012, 10:04:10 AM

Previous topic - Next topic

lifeofdave

Hi all,

I'm using php to interact with exiftool via the command line and occasionally it fails  to read any custom exif tags.

PHP looks like this:
$exifArray = eval('return ' . `exiftool -c "%+.6f" -gpspitch  -php $fullPhotoPath`);

This works great but will suddenly stop working here and there. The odd thing is that the same command that fails to get custom tags through php works fine if I type it directly into the terminal.

When it works, code above produces this array in browser:

Array ( [0] => Array ( [SourceFile] => /var/www/html/thumb_IMG_6706-JPG.jpg [GPSPitch] => -34 ) ) 

When it stops working, code above produces this array in the browser:
Array ( [0] => Array ( [SourceFile] => /var/www/html/thumb_IMG_6706-JPG.jpg ) )

But the output in terminal using the same command is correct:

#  exiftool -c "%+.6f" -gpspitch -php /var/www/html/thumb_IMG_6706-JPG.jpg
Array(Array(
  "SourceFile" => "/var/www/html/thumb_IMG_6706-JPG.jpg",
  "GPSPitch" => -34
));



The original solution was to restart my whole server, which did the trick.

Now it's happened again a new solution is to specify the config file in the command like so:
$exifArray = eval('return ' . `exiftool -config /.ExifTool_config -c "%+.6f"  -php $fullPhotoPath`);

This suggests that when it fails it isn't using the custom exiftool config, but then what would make it do that?
I'm curious as to what's happening. Any ideas?

Dave

Phil Harvey

Hi Dave,

Where is your config file located, and do you have different versions of exiftool lying around?

What exiftool is run, and what config file is loaded depends on your environment settings, which may be different from within a PHP file.  To avoid succumbing to environment problems, I suggest running exiftool with a full path specification and using the -config option as you do with a full path specification on the config file too.

I don't know why the environment should change between runs within PHP, but then again I'm not a PHP programmer so I'm not really the one to ask about this.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).