title: decode base64 image data posted from android to save image on php server
body: <p>I am developing a web service to upload image from android device to server using php script where image data in the form of base64 string is sent from android device to server using http post request. And at server end I am using following code to decode image data and save image to the server:</p>
  
  <pre><code>$json = file_get_contents('php://input');
  $obj = json_decode($json);
  $base = $obj-&gt;image;
  $ext = $obj-&gt;extension;
  $folderPath = "./logo/";
  $fileName = 'logo_'.$time.'.'.$ext;
  
  $binary = bin2hex(base64_decode($base));
  $data = pack("H" . strlen($binary), $binary);
  $file = fopen($folderPath.$fileName, 'wb');
  fwrite($file, $data);
  fclose($file);
  </code></pre>
  
  <p>This code is saving image data on the server but image data is not same as data posted by android application. Even size of uploaded file does not match with original file. <br>
  So can anyone help me in this so that image data sent from android application decoded properly and saved in image file same as image sent from android?</p>