First let me say that although I have put together various web pages/functions in the past by 'hacking' 3rd party scripts to suit my needs, I am not a coder or programmer.

I recently took up photography and rather than use one of the proprietary photo sites I am currently slowly putting together a personal web site for uploading/storing/displaying potographs.

I have a script for the upload which uploads (one at a time) photographs then resizes it to 2 different sizes and stores all 3 photos in specified (in the code) directories.

The second script was developed to open a photograph (name and location hard coded) extract exif data from the photograph and display the image and data on a web page.

In this script I had to add a calculation to display 2 of the fields in a particular way. Just for info, the fields are the GPS co-ordinates for latitude/longitude which are stored in the photograph as Degrees/Minutes/Seconds and I need to display them in decimal.

Now here is where I have run into a problem.

I combined the 2 scripts so that when the upload is complete the second script kicks in and displays the info for the original sized image. (The next step will be to place that info in a SQL database.)
The combined script works in principle, but what is missing is the calculated information.

The only change I made to the second script (which is called as an 'include' by the firs)t was to the variable specifying the image name and its location.

I changed this code;
// --- Change the 'image1.jpg' value below to the path of your file. --- //

$Image = 'original/test.jpg';

// --- Read EXIF Data --- //

$exif = exif_read_data($Image, 0, true);
to this: ($Image99 is a variable set in the upload script to specify the name and location of the uploaded image).

// --- Change the 'image1.jpg' value below to the path of your file. --- //

$Image = $Image99;

// --- Read EXIF Data --- //

$exif = exif_read_data($Image, 0, true);
The code which works in the stand alone script but fails in the combined one is this:

// --- The EXIF GPS Conversion Degrees to Decimal --- //

function toDecimal($deg, $min, $sec, $hemi) {
 $d = $deg + $min/60 + $sec/3600;
 return ($hemi=='S' || $hemi=='W') ? $d*=-1 : $d;

function divide($a) {
 $e = explode('/', $a);
 if (!$e[0] || !$e[1]) {
  return 0;
 } else {
  return $e[0] / $e[1];

function getGPS() {
 global $exif;
 if ($exif) {  $lat = $exif['GPS']['GPSLatitude'];
 $log = $exif['GPS']['GPSLongitude'];
  if (!$lat || !$log) return null;
  $lat_degrees = divide($lat[0]);
  $lat_minutes = divide($lat[1]);
  $lat_seconds = divide($lat[2]);
  $lat_hemi = $exif['GPS']['GPSLatitudeRef'];
  $log_degrees = divide($log[0]);
  $log_minutes = divide($log[1]);
  $log_seconds = divide($log[2]);
  $log_hemi = $exif['GPS']['GPSLongitudeRef'];
  $lat_decimal = toDecimal($lat_degrees, $lat_minutes, $lat_seconds, $lat_hemi);
  $log_decimal = toDecimal($log_degrees, $log_minutes, $log_seconds, $log_hemi);
  return array($lat_decimal, $log_decimal);
 } else{
  return null;

 $gps = getGPS();
// --- end EXIF GPS Conversion Degrees to Decimal --- //

What I fail to understand is why the second script works fully as a stand alone, but misses info when 'included'.

I have tried to find a solution elsewhere with no success, and am hoping someone of experience here can tell me how I could go about doing an analysis to determine where the problem is arising (remembering I have little experience in this area at this time).