我在我的 PHP 代码中调用了一个返回 JSON 的 Rest API。我想将其中的某些部分保存到我的数据库中,但由于某种原因,没有存储任何内容。这是 JSON 的样子:
{
"url": "http://myURL.com/fujifilm-mx1700.jpg",
"mimeType": "image/jpeg",
"width": 640,
"height": 480,
"byteSize": 100227,
"exif": {"YResolution": "72/1", "Tag0xa217": "2", "ResolutionUnit": "Inch", "Compression": "6", "Copyright": "", "Tag0xa300": "[ 3 ]", "Make": "FUJIFILM", "Flash": "no", "DateTime": "2000:09:02 14:30:10", "MaxApertureValue": "3.3", "YCbCrPositioning": "2", "XResolution": "72/1", "JPEGInterchangeFormatLength": "4354", "ExposureBiasValue": "0.0", "ExposureProgram": "Program Normal", "ShutterSpeedValue": "1/169", "ColorSpace": "1", "Tag0xa20e": "1087/1", "Tag0xa20f": "1087/1", "ExifImageWidth": "640", "DateTimeDigitized": "2000:09:02 14:30:10", "DateTimeOriginal": "2000:09:02 14:30:10", "BrightnessValue": "76/10", "CompressedBitsPerPixel": "2/1", "Interoperability_IFD_Pointer": "708", "FNumber": "7", "ApertureValue": "5.6", "Tag0xa210": "3", "FocalLength": "9.9", "Tag0xa000": "[ 48,49,48,48 ]", "ComponentsConfiguration": "[ 1,2,3,0 ]", "ExifImageHeight": "480", "ISOSpeedRatings": "125", "Model": "MX-1700ZOOM", "Software": "Digital Camera MX-1700ZOOM Ver1.00", "Orientation": "1", "Tag0xa301": "[ 1 ]", "JPEGInterchangeFormat": "856", "MeteringMode": "5", "ExifVersion": "[ 48,50,49,48 ]"}
}
这是我的 PHP
$exif = file_get_contents('http://img2json.appspot.com/go/?url=http://myURL.com/$fileName');
$response = json_decode($response, true);
foreach($response['exif'] as $item) {
$iso = $item['ISOSpeedRatings'];
$shut = $item['ShutterSpeedValue'];
$sql="INSERT INTO EXIF (uniqueID, ISO, shutterSpeed)
VALUES('$id','$iso','$shut')";
if (!mysql_query($sql,$link)) {
die('Error: ' . mysql_error());
}
}
我想将 ISOSpeedRatings 和 ShutterSpeedValue 存储在我的数据库中,但它们一直是空的。
我怀疑它不起作用,因为我没有从 JSON 中正确检索我想要的数据,但我不太确定该怎么做。另外,我认为值得注意的是我正在使用 AppFog,所以我必须确保我php_value allow_url_fopen 1
的 .htaccess 中有,因为我无法访问 php.ini 文件。任何帮助,将不胜感激。