dongyuluan7494 2013-06-25 06:45
浏览 77
已采纳

使用php从iphone app处理json base64编码图像

I am working on a php REST API that will be used with an iPhone app. It is another developer who develops the app. From that app it is possible to take a image and upload it to the webserver. I will recieve the images from the iphone as base64 with json, but I am unsure how to process them with a PHP script. The images will be send like:

{
"image1":"Base64Data",
"image2":"Base64Data",
"image3":"Base64Data",
"image4":"Base64Data"
}

will it be something like:

$image1 = json_decode($jsonData);

Is it possible to get the same / a like data from the base64 string as from $_FILES[] upload? When images a upload the normal way from the website, they are being handled with a cropper and thumbnail generator. I want the base64 images to be handled the same way.

  • 写回答

2条回答 默认 最新

  • doujing5937 2013-06-25 06:53
    关注

    your json which looks like this

    {
    "image1":"Base64Data",
    "image2":"Base64Data",
    "image3":"Base64Data",
    "image4":"Base64Data"
    }
    

    will not be something like:

    $image1 = json_decode($jsonData);
    

    more like this

    $json = json_decode($jsonData, true);
    $image1 = $json['image1'];
    

    There will be no values similar to $_FILES except the data of the file.

    you can easily do

    $imagedata = base64_decode($image1);
    file_put_contents("file.jpg", $imagedata);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?
  • ¥15 ubuntu系统下挂载磁盘上执行./提示权限不够
  • ¥15 Arcgis相交分析无法绘制一个或多个图形
  • ¥15 关于#r语言#的问题:差异分析前数据准备,报错Error in data[, sampleName1] : subscript out of bounds请问怎么解决呀以下是全部代码:
  • ¥15 seatunnel-web使用SQL组件时候后台报错,无法找到表格
  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误