私のサーバーに画像をアップロードしようとすると、今は失われています。私は写真を撮って、Androidデバイス上で自分の位置を取得することができます。ファイルをサーバーにアップロードするためのコードがあります。サーバーに画像をアップロードするPHP Android
public Boolean postFunction(File image) {
String tag = "postFunction";
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(UPLOAD_URL);
try {
MultipartEntity entity = new MultipartEntity();
entity.addPart("type", new StringBody("photo"));
entity.addPart("data", new FileBody(image));
httppost.setEntity(entity);
HttpResponse response = httpclient.execute(httppost);
Log.i(tag, "picture was uploaded " + response.toString());
return true;
} catch (ClientProtocolException e) {
Log.e(tag, "Client: " + e.toString());
return false;
} catch (IOException e) {
Log.e(tag, "IO: " + e.toString());
return false;
}
}
私はこの機能に画像ファイルを渡してアップロードします。しかし、エラーは私が信じるサーバー側にある。ここで
は私のPHPコードです:
public function upload() {
//$type = $this->input->post('type');
//$data = $this->input->post('data');
$base = $_REQUEST['data'];
echo $base;
// base64 encoded utf-8 string
$binary = base64_decode($base);
// binary, utf-8 bytes
header('Content-Type: bitmap; charset=utf-8');
// print($binary);
//$theFile = base64_decode($image_data);
$file = fopen('./test.jpg', 'wb');
fwrite($file, $binary);
fclose($file);
echo '<img src=test.jpg>';
}
ファイルが触れたが、まだ空白のままされます。私はここに何かを逃していますか助けてください、私はこれをグーグルで試しましたが、私にはあまり役に立たなかった別の結果が出ました。