php - 无法从 PHP 中的大文件的 Img2Json API 获取 JSON 数据

标签 php mysql json amazon-s3

我正在使用 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/olympus-c960.jpg

两个失败:http://img2json.appspot.com/go/?callback=hello&url=http://cloudousmain.s3.amazonaws.com/54img.JPG

http://img2json.appspot.com/go/?callback=hello&url=http://cloudousmain.s3.amazonaws.com/IMG_20130329_120227.jpg

我在 ini 文件中增加了内存但没有成功。此外,可能值得注意的是,在处理图像时会显示一个进度条,直到事情完成(或应该完成)。有什么想法吗?

编辑:切换到 curl 并使用 var_dump 显示“不起作用”的图像被转储为 NULL,而工作正常的图像按预期为我提供了一组 Exif 数据。

最佳答案

看起来是 AWS 错误,它是用 XML 编写的,无法解析 EXIF 数据。当我尝试在浏览器中查看不良图像时出现“访问被拒绝”,但良好的图像显示图像。

要在代码中检查这一点,ping 图像文件的 header 并检查内容类型是否为 application/xml 或者 http 代码是否为 403。我建议使用 http_head() 或在 curl_setopt() 中标记 CURLOPT_HEADER 以获得此信息。

关于php - 无法从 PHP 中的大文件的 Img2Json API 获取 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20013535/

相关文章:

android - 如何在微调器中设置初始文本而不是 json 响应的第一项

c# - 无法将类型 'System.Web.Mvc.RedirectToRouteResult' 隐式转换为 'System.Web.Mvc.JsonResult'

javascript - javascript创建对象的两种方式

php - PHP 中的 __halt_compiler 有什么用?

php - iPhone 手机 safari JSON 解析错误

php - 具有 Symfony 3/Doctrine 属性形式的一对多对一

php - 将多项选择下拉列表保存到 1 列中

mysql - SQL 并排显示来自不同表的两列数据,无需连接

php - 谷歌地图绘制

php - 删除 PHP 中的换行符 - 但它们仍显示在 MySQL 的 LONGTEXT 中