【发布时间】:2015-05-24 13:53:51
【问题描述】:
我正在尝试将图像上传到服务器,但 base64_decode 总是返回 null
我从 SO 中阅读了很多不同的案例,但没有任何效果。
这是我发出 http 请求之前的 java 代码:
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代码:
$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);
我也试过$file = fopen($imagepath, 'wb'); 仍然$binary 总是返回null;
有人可以帮助我了解问题所在吗?
我还检查了$base,它看起来没问题,我也尝试删除\n 或\\,但没有任何帮助
【问题讨论】: