基本解码64阵列上传

时间:2014-02-28 15:12:12

标签: php arrays base64

我似乎不能编码和保存图像。我已经剥离了base64,但仍然没有快乐。

输出

$random echo = 838e8afb1ca34354ac209f53d90c3a43jpg

Array
    (
        [0] => Array
            (
                [id] => 0
                [storename] => test
                [notes] => test
                [image] => 503316
            )

    )

PHP

$random = md5(rand()).".jpg";

echo $random;

$image = preg_replace('#^data:image/[^;]+;base64,#', '', $data['image']);

$nonerejected[] = array(
             'id' => $data['id'],
             'storename' => $data['storename'],
             'notes' => $data['notes'],
             'image' => $data['image'] == "" ? "" : file_put_contents($random,base64_decode($image)),   
                );

如果我回显$ image

  

9j / 4AAQSkZJRgABAQAAAQABAAD // gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2..goes on for some ..

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

放置外部阵列。

            $random = md5(rand()).".jpg";
            $image = preg_replace('#^data:image/[^;]+;base64,#', '', $data['image']);

                file_put_contents($random,base64_decode($image))    ;

                $nonerejected[] = array(
                    'id' => $data['id'],
                    'storename' => $data['storename'],
                    'notes' => $data['notes'],
                    'image' => $random, 

                );
            }