Jump to content

Information not being displayed


pewe

Recommended Posts

I had need to combine 2 separate scrips (as detailed in another post now marked as resolved).

 

I have now managed to combine the 2 scripts and get them working together.

 

However I have one very strange problem.

 

- The function of the first script is to upload an image, create 2 new sizes of it and store all 3 images in separate directories on the server.

 

- The function of the second script is to read the Exif data from an image specified in the script and to then display the image and the exif data in a formatted page.

 

Independently these scripts work perfectly.

 

I have now modified the first script on completion of upload and storage of the image to load the location and name of the stored original image as a variable and then to run the second script.

 

I modified the second script to load the variable from the first script to identify the image to process instead of using a hard coded reference to the image and location.

 

The new combined script works as required EXCEPT for one problem.

 

In the second script, once the exif data is loaded from the image there is a calculation done on 2 of the elements and the results of the calculation are then displayed.

 

The results of this calculation are missing when I run the new script, but they show perfectly if I run the original script using hard coding to point to the same image the combined script uses.

 

The ONLY change I made to the second script was to the image location:

 

This in the stand alone version:

 

// --- 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);

// --- 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();

 

This is the modified version;

 

// --- 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 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();

 

$Image99 in the second set of code is the location of the image defined as a variable in the upload part of the script - and is the same image used in the standalone script.

 

So - can anyone point me in the direction of how to locate the problem with the combined script.

 

Here's hoping for some guidance.

Link to comment
Share on other sites

Have you verified the information obtained here: $Image = $Image99;

 

From what you posted that's pretty much all you modified, so I'm taking a guess here. Before it was hard coded, now you're passing a variable and is it escaped properly?

Link to comment
Share on other sites

Have you verified the information obtained here: $Image = $Image99;

 

Yes - that is working -  when the second script is launched, it displays the image that was uploaded and all the exif data EXCEPT the calculated part (the decimal calculation shown above).

 

What I don't understand is why the calculated part is not working when the script is 'included' with the upload script, but works when I call the same script with the same image (although the image is hardcoded and not called from a variable).

Link to comment
Share on other sites

That's why I wanted to see what the variable data was, it may not be sending the '/' properly or something along those lines.. I seen your aggravation and that's why I'm jumping in to see if we can brainstorm together.

 

Since the scripts work if used independent of each other and the only difference is now they are combined, then the variable has to be part of the issue. Separate the scripts again and have the first script send the variable from a form to the 2nd script and see if that works.

Link to comment
Share on other sites

Thanks Kadeous - but I managed to solve the problem.

 

This was done by simply moving the script that created the variable and called the 'include' to a different part of the script (ie from the middle to the bottom) and enclosing it in php tags (<?....?>).

 

I don't know why this worked - but it did.

 

Thanks again.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.