Php 解码阵列中的基64
我正试图通过post请求将base64映像保存到Web服务器中,目前我的数组如下所示Php 解码阵列中的基64,php,arrays,base64,Php,Arrays,Base64,我正试图通过post请求将base64映像保存到Web服务器中,目前我的数组如下所示 ( [0] => Array ( [id] => 0 [storename] => test [notes] => test [image] => data:image/jpeg;base64,/9j/4........to long 当我试图更新我的代码以允许
(
[0] => Array
(
[id] => 0
[storename] => test
[notes] => test
[image] => data:image/jpeg;base64,/9j/4........to long
当我试图更新我的代码以允许解码和保存时,我从图像中得到的回音是一个数字
PHP
$random = md5(rand());
$nonerejected[] = array(
'id' => $data['id'],
'storename' => $data['storename'],
'notes' => $data['notes'],
'image' => $data['image'] == "" ? "" : file_put_contents(''.$random.'.JPG',base64_decode($data['image'])),
);
阵列输出
(
[0] => Array
(
[id] => 0
[storename] => test
[notes] => test
[image] => 503331
)
)
有什么想法吗,伙计们 数据:图像/jpeg;base64,位不是base64,所以base64实际上不能用它做任何事情。为了存储文件,您必须将其剥离。base64\u decode()只需要base64数据。数据uri不是b64数据的一部分,它会损坏已解码的字符串。我如何删除它?它只是一个字符串。使用substr()我应该用什么来去除它?Hacky方法:
$image=array_pop(explode(',base64',,$data['image',2))对不起?我不明白你的问题?很抱歉,我在代码中添加了get:Runtime注意:只有变量应该通过inOh引用传递,这是可以选择忽略的。如果您想解决它:$parts=explode(',base64',$data['image',2)$图像=数组_pop($parts)代码>