I am trying to upload an image to server but base64_decode
always returns null
i read a lot of different cases from SO but nothing works.
here is my java code before i make my http request:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
// Must compress the Image to reduce image size to make upload easy
bitmap.compress(Bitmap.CompressFormat.PNG, 50, stream);
byte[] byte_arr = stream.toByteArray();
// Encode Image to String
encodedString = Base64.encodeToString(byte_arr,Base64.NO_WRAP);
params.add(new BasicNameValuePair(TAG_IMAGE, encodedString));
...and the http request
php code:
$base=$_REQUEST['image'];
//$response["base"] = $base;
$binary=base64_decode($base,TRUE);
$response["binary"] = $binary;
header('Content-Type: bitmap; charset=utf-8');
$imagepath='the path of the image';
$file = fopen($imagepath, 'w');
fwrite($file, $binary);
fclose($file);
i also tried $file = fopen($imagepath, 'wb');
still $binary
is always return with null
;
somebody can please help me understand what is the problem?
also i checked $base
and it looks ok, i also tried to remove
or \\
but nothing helps