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:
$json = file_get_contents('php://input');
$obj = json_decode($json);
$base = $obj->image;
$ext = $obj->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);
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.
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?