在Array中解码Base 64

时间:2014-02-28 14:30:46

标签: php arrays base64

我试图从发布请求中将base64图像保存到网络服务器中,目前我的数组看起来像这样。

(
    [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
    )

任何想法的家伙?

1 个答案:

答案 0 :(得分:1)

data:image/jpeg;base64,位不是base64,因此base64无法对它做任何事情。你必须将其剥离才能存储你的文件。