我正在使用 http://img2json.appspot.com/检索和存储用户上传图像的 Exif 数据。我注意到对于较小的文件,效果很好。对于较大的文件,或包含大量 Exif 数据的文件,将存储文件但不存储 Exif 数据。我不知道这是因为服务生成 JSON 的时间太长,还是因为我将所有 JSON 存储在 PHP 数组中而出现内存问题。
我检索用户上传图片的 Exif 数据的代码如下:
$exifd = file_get_contents("http://img2json.appspot.com/go/url=http://myURL.com/$fileName");
$response = json_decode($exifd, true);
$shut = $response['exif']['ShutterSpeedValue'];
$iso = $response['exif']['ISOSpeedRatings'];
$dateTime = $response['exif']['DateTime'];
$aperture = $response['exif']['ApertureValue'];
$focalLength = $response['exif']['FocalLength'];
$make = $response['exif']['Make'];
$model = $response['exif']['Model'];
$software = $response['exif']['Software'];
$flash = $response['exif']['Flash'];
$sql="INSERT INTO EXIF (uniqueID, dateTime, aperture, focalLength, make, model, software, shutterSpeed, ISO, flash)
VALUES('$id', '$dateTime', '$aperture', '$focalLength', '$make', '$model', '$software', '$shut', '$iso', '$flash')";
if (!mysql_query($sql,$link))
{
die('Error: ' . mysql_error());
}
}else{
echo "Something went wrong while uploading your file... sorry.";
}
正如我之前提到的,这在大多数情况下效果很好,但它不适用于大文件(大文件或 Exif 数据量大),有时小文件也会失败。
两个失败:http://img2json.appspot.com/go/?callback=hello&url=http://cloudousmain.s3.amazonaws.com/54img.JPG
和
我在 ini 文件中增加了内存但没有成功。此外,可能值得注意的是,在处理图像时会显示一个进度条,直到事情完成(或应该完成)。有什么想法吗?
编辑:切换到 curl 并使用 var_dump 显示“不起作用”的图像被转储为 NULL,而工作正常的图像按预期为我提供了一组 Exif 数据。
最佳答案
看起来是 AWS 错误,它是用 XML 编写的,无法解析 EXIF 数据。当我尝试在浏览器中查看不良图像时出现“访问被拒绝”,但良好的图像显示图像。
失败:http://cloudousmain.s3.amazonaws.com/54img.JPG
<Error> <Code>AccessDenied</Code> <Message>Access Denied</Message> <RequestId>2537951DEE216FEB</RequestId> <HostId>Ep4//A7Oq+n/C3ilB5jyazx0Bs9fQfMRyNg+pX/rs+dkziFhJIkgHNWHc+CAZVgR</HostId> </Error>
要在代码中检查这一点,ping 图像文件的 header 并检查内容类型是否为 application/xml
或者 http 代码是否为 403。我建议使用 http_head()
或在 curl_setopt()
中标记 CURLOPT_HEADER
以获得此信息。
关于php - 无法从 PHP 中的大文件的 Img2Json API 获取 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20013535/