<?php
// read_exif_off_image.php
// RJM Programming
// August, 2016
// Thanks to http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data
$nform="<br><form action='./read_exif_off_image.php' method='POST'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Image URL: <input name='image' id='image' type='text' value=''></input>&nbsp;&nbsp;<input type='submit' value='Exif Information'></input></form>";

if (isset($_GET['image'])) {
  $image = urldecode($_GET['image']);
} else if (isset($_POST['image'])) {
  $image = urldecode($_POST['image']);
} else {
  $image = "/Applications/MAMP/htdocs/clouds.jpg";
}

$types = array(
1 => "GIF",
2 => "JPEG",
3 => "PNG",
4 => "SWF",
5 => "PSD",
6 => "BMP",
7 => "TIFF",
8 => "TIFF"
);

$imagetype = exif_imagetype($image);

if (array_key_exists($imagetype, $types)) {
 echo "<!doctype html><html><head><title>Exif for " . $image . "</title></head><body style='background-color:pink;'><h1>Exif for " . $image . "</h1><h3>RJM Programming - August, 2016</h3><h4>Thanks to <a target=_blank title=Useful href=http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data>http://www.v-nessa.net/2010/08/02/using-php-to-extract-image-exif-data</a></h4><div style='background-color:yellow; background: url(" . str_replace("/Applications/MAMP/htdocs/","http://localhost:8888/",$image) . ");'><br>" . "Image type of " . $image . " is: " . $types[$imagetype];
 $exif = exif_read_data($image, 0, true);
 foreach ($exif as $key => $section) {
  foreach ($section as $name => $val) {
   echo "<br>" . "$key.$name: $val";
  }
 }
 echo "</div>" . $nform . "</body></html>";
} else {
 echo "<br>" . "Not a valid image type for " . $image . " or Exif functionality not enabled." . $nform;
}
?>