Reading Exif data with PHP

Within most photos from digital cameras besides the actual image, there’s a little ”information block” call EXIF data. If you have the correct PHP extension installed on your server – the one called ”exif” – it’s pretty easy to read the EXIF data and display them, as you like.

First, let’s check if the extension is available?

$load\_ext = get\_loaded\_extensions();
if (!in\_array(exif, $load\_ext)) {
echo "Exif is NOT available";
} else {
echo "Exif extension is available.";

If you have the extension available, reading the data is a simple matter:

$nikonFile   = './aarhus\_demo\_photo.jpg';
$exifNikon   = getExifData($nikonFile);

$olympusFile = './zanzibar\_demo\_photo.jpg';
$exifOlympus = getExifData($olympusFile);

echo "<h2>Olympus EXIF data</h2>";
echo "<pre>";
echo "</pre>";

echo "<h2>Nikon EXIF data</h2>";
echo "<pre>";
echo "</pre>";

function getExifData($file) {
$exif = exif\_read\_data($file, 0, true);
return $exif;

As you may notice, there’s a photo from an Olympus camera and a Nikon camera as an example. The data available from each photo isn’t quite the same. Most generic fields are available, but some fields are camera specific (or maker specific).

See the example above in action (source). The two images are from Aarhus (Nikon) and Zanzibar (Olympus). You can read more on EXIF in Wikipedia.