EXIF error handling

I am writing a new gallery and want to read the EXIF data and save it to a database. I have three types of error to deal with that I can think of:

1/ EXIF data not supported - png image.
2/ No EXIF data in the file but EXIF data supported.
3/ This error “Incorrect APP1 Exif Identifier Code” In one case this could be caused by converting a CR2 file to a TIFF file via some HDR software and then saving as a jpg.

I think I have delt with 1/ and 2/ but 3/ crashes my code and the data is not saved to the database. The code I am using is below; any ideas on dealing with error 3/ and any improvements that could be made to my code ?
Note the bad photo is still uploaded just the EXIF part fails.


/*** Check if the image supports EXIF data ***/
if( exif_read_data( $tempory_location )){

	/*** Get EXIF info ***/
	$exif_data = @exif_read_data ( $tempory_location );
	( empty($exif_data['Make']) ? $make = 'Unknown' : $make = $exif_data['Make']);
	( empty($exif_data['Model']) ? $model = 'Unknown' : $model = $exif_data['Model']);
	( empty($exif_data['ExposureTime']) ? $exposure = '0' : $exposure = $exif_data['ExposureTime']);
	$exposure = htmlentities( $exposure );
	( empty($exif_data['FNumber']) ? $fnumber = '1/1' : $fnumber = $exif_data['FNumber']);
	$f_parts = explode('/', $fnumber);
	$f = round(( $f_parts[0]/$f_parts[1]),2);
	( empty($exif_data['ISOSpeedRatings']) ? $iso = '0' : $iso = $exif_data['ISOSpeedRatings']);
	( empty($exif_data['DateTime']) ? $date = '1:1:1' : $date = $exif_data['DateTime']);


	/*** Convert date to timestamp ***/
	list( $year, $month, $day) = explode(':', $date);
	$timestamp = mktime(0, 0, 0, (int)$month, (int)$day, (int)$year);
	}
	

/*** If EXIF headers not supported do this ***/
else {
	$make = 'Unknown';
	$model = 'Unknown';
	$exposure = '1/1';
	$f = '0';
	$iso = '0';
	$timestamp = mktime(0, 0, 0, 0, 0, 0); 
}

Looks like 3/ is not crashing my code - I did not have the insert privilage set for the database user :nono:

I could suppress the error with a @ if there is no other way.

I have created myself a little function and I can lose the not supported EXIF part and just add @ to the EXIF read function to supress the error.
Remove this:


/*** If EXIF headers not supported do this ***/ 
else {
     $make = 'Unknown';
     $model = 'Unknown';
     $exposure = '1/1';
     $f = '0';
     $iso = '0';
     $timestamp = mktime(0, 0, 0, 0, 0, 0);
  }  

The function:


/*** Setup the values for the EXIF data ***/
function EXIF_defaults( $input, $default ){	
empty($input) ? $adjustment = $default : $adjustment = $input;
// Calculate the F number
if ( $default == '1/1' ){
$f_parts = explode('/', $adjustment);
$adjustment = round(( (int)$f_parts[0]/(int)$f_parts[1]),2);	
}
// Convert the date to a timestamp
if ( $default == '1:1:1' ){
list( $year, $month, $day) = explode(':', $adjustment);
$adjustment = mktime(0, 0, 0, (int)$month, (int)$day, (int)$year);	
}		
return htmlentities( $adjustment );
}