2014-02-28 82 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, 

       ); 
      }