title: PHP base64 encoded image not displaying correctly
body: <p>I'm trying to send an image (any size) over to an API I'm creating, using base64 encoding. The encoded string hits my API as a parameter in the URL. The API built with PHP.</p>
  
  <p>Once the request hits my API, I want to store the image onto my server, and save the file name in the database.  This is working, however I'm getting some odd outputs with the actual image.</p>
  
  <p>For reference, I also followed <a href="http://blog.justin.kelly.org.au/simple-base64-encodedecode-url-safe-functions/" rel="nofollow noreferrer">http://blog.justin.kelly.org.au/simple-base64-encodedecode-url-safe-functions/</a> but have the same results.</p>
  
  <p>The image I am trying to store on my server:</p>
  
  <p><img src="https://i.stack.imgur.com/OVNAN.jpg" alt="enter image description here"></p>
  
  <pre><code>$encode = base64_encode(file_get_contents($image));
  
  echo $encode;
  </code></pre>
  
  <p>For testing, the ouput of this is the string I'm using to pass to my API.</p>
  
  <p>In the API:</p>
  
  <pre><code>$image = base64_decode($_POST['image']));
  $image_name = md5($image) . ".jpg";
  file_put_contents(/public/image/ . $image_name, $image);
  </code></pre>
  
  <p>This works, my image is put onto the server in the correct directory with a random name which is saved to the database.</p>
  
  <p>However, when navigating to the image directly, the image is warped:</p>
  
  <p><img src="https://i.stack.imgur.com/ReKfp.jpg" alt="enter image description here"></p>
  
  <p>If you have a sharp eye, the top part of the image is actually correct before it starts to fail, which makes me start to think whether the string is not getting encoded correctly to be sent as a parameter?</p>
  
  <p>Any clues would be lovely, cheers.</p>
  
  <p>EDIT: Changed it to POST, removed urlencode/decode &amp; removed <code>strtr</code>.</p>