title: Base Decode 64 Array Upload
body: <p>I cant seem to base encode and save an image. I have stripped the base64 but still no joy.</p>
  
  <p><strong>Output</strong></p>
  
  <pre><code>$random echo = 838e8afb1ca34354ac209f53d90c3a43jpg
  
  Array
      (
          [0] =&gt; Array
              (
                  [id] =&gt; 0
                  [storename] =&gt; test
                  [notes] =&gt; test
                  [image] =&gt; 503316
              )
  
      )
  </code></pre>
  
  <p><strong>PHP</strong> </p>
  
  <pre><code>$random = md5(rand()).".jpg";
  
  echo $random;
  
  $image = preg_replace('#^data:image/[^;]+;base64,#', '', $data['image']);
  
  $nonerejected[] = array(
               'id' =&gt; $data['id'],
               'storename' =&gt; $data['storename'],
               'notes' =&gt; $data['notes'],
               'image' =&gt; $data['image'] == "" ? "" : file_put_contents($random,base64_decode($image)),   
                  );
  </code></pre>
  
  <p><strong>If I echo $image</strong></p>
  
  <blockquote>
    <p>9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2..goes on for some.. </p>
  </blockquote>
  
  <p>Any ideas?</p>