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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里