2014-02-28 33 views
0

我似乎不能编码和保存图像。我已经剥离了base64,但仍然没有喜乐。基地解码64阵列上传

输出

$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)), 
       ); 

如果我回声$图像

9J/4AAQSkZJRgABAQAAAQABAAD // gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wI Ch1c2luZyBJSkcgSlBFRyB2 .. goes一些..

任何想法?

+0

唯一与base64相关的方法调用是'base64_decode()'。顾名思义就是解码;它不编码。你如何期望base64编码的东西没有像'base64_encode()'这样的方法调用? –

+3

你为什么在你的数组定义中做file_put_contents?这没有任何意义。 –

回答

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, 

       ); 
      }