The PHP application will run on Google App Engine. It should be able to read EXIF information from user-uploaded photos, especially the camera brand and model, f number, focal length, GPS coordinates etc.
Reading from a temporary file
When the script tries to read EXIF directly from the uploaded files like this:
$exif = exif_read_data($_FILES['file']['tmp_name']);
the results are following:
Local PHP server (PHP 7.1.9) - Ok
Google Cloud SDK (182.0.0, PHP 5.5.26)
Warning: exif_read_data(0): Error reading from file: got=x3FFA(=16378) != itemlen-2=xF2A8(=62120) in D:\project\upload.php on line 5
Warning: exif_read_data(0): Invalid JPEG file in D:\project\upload.php on line 5
Google App Engine (PHP 5.5.38)
PHP Warning: exif_read_data(0): Error reading from file: got=x3FFA(=16378) != itemlen-2=xF2A8(=62120) in /base/data/home/apps/e~project/20171226t213042.406490485858874687/upload.php on line 5
PHP Warning: exif_read_data(0): Invalid JPEG file in /base/data/home/apps/e~project/20171226t213042.406490485858874687/upload.php on line 5
I suspect it has to do with the way Google stores the uploaded files in a virtual file system (tmp_name is vfs://root/uploads/0
).
Reading from a file in Google Storage bucket
When I move the uploaded photo to a GS bucket and then try to read the EXIF from there:
use google\appengine\api\cloud_storage\CloudStorageTools;
$bucket = CloudStorageTools::getDefaultGoogleStorageBucketName();
$name = $_FILES['file']['name'];
$tmp_name = $_FILES['file']['tmp_name'];
$file_path = 'gs://' . $bucket . '/' . $name;
move_uploaded_file($tmp_name, $file_path);
$serving_url = CloudStorageTools::getImageServingUrl($file_path);
$exif_raw = exif_read_data($serving_url);
the results are following:
Google Cloud SDK
Warning: exif_read_data(encoded_gs_file:YXBwX2RlZmF1bHRfYnVja2V0L0dPUFIwNTMxLkpQRw==): Error reading from file: got=x3FFA(=16378) != itemlen-2=xF2A8(=62120) in D:\project\upload.php on line 17
Warning: exif_read_data(encoded_gs_file:YXBwX2RlZmF1bHRfYnVja2V0L0dPUFIwNTMxLkpQRw==): Invalid JPEG file in D:\project\upload.php on line 17
Google App Engine - EXIF can be read but it seems that only FILE and COMPUTED sections are available; information from IFD0 or EXIF sections which contain the camera-related information is missing.
How can the app read EXIF (including IFD0 section) both on the local development server and Google App Engine?