使用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.
我正在开发一个将与iPhone应用程序一起使用的php REST API。 这是另一个开发应用程序的开发人员。 从该应用程序可以拍摄图像并将其上传到网络服务器。 我将使用json将iphone中的图像作为base64接收,但我不确定如何使用PHP脚本处理它们。 图像将发送如下: p>
{\ N “image1的”: “Base64Data”
“个图像2”: “Base64Data”
“个图像3”: “Base64Data”
“个图像4”: “Base64Data” \ N}
代码> 预 >
它是这样的: p>
$ image1 = json_decode($ jsonData);
code> pre>
\ n 是否可以从base64字符串获取与 $ _ FILES [] code>上传相同/类似的数据? 当图像以正常方式从网站上传时,它们将使用裁剪器和缩略图生成器进行处理。 我希望base64图像以相同的方式处理。 p>
div>
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);
You can decode Base64 encoded, with this: base64_decode($yourstring)
Also, you can decode the Json and after the Base 64 encoded.