使用安卓 studio和mysql进行第二次照片更新的java
我在安卓 studio和mysql中更新照片档案时遇到了一些问题。但对于数据库更新的过程来说没有问题,照片更新成功。第一次在imageview中更新照片配置文件成功更改,并将照片上传到xampp内的文件夹“upload”,第二次更新不会更改,而是在imageview中使用上一次更新。但在xampp内的文件夹“upload”中,以前的照片会随着我以前上传的新照片而改变。我试图用onRestart()刷新活动,但失败了,希望您理解我的问题。请帮帮我
here the php code :
<?php
include "koneksi.php";
$gambar = $_POST['foto'];
$id = $_POST['id_user'];
class emp{}
$path = "profil_upload/$id.png";
$actualpath = "http://192.168.173.1/StudioFoto/$path";
$query = mysql_query("UPDATE user SET foto='".$actualpath."' WHERE id='".$id."'");
if ($query) {
file_put_contents($path,base64_decode($gambar));
$response = new emp();
$response->success = 1;
$response->message = "Data berhasil di simpan";
die(json_encode($response));
} else{
$response = new emp();
$response->success = 0;
$response->message = "Error simpan Data";
die(json_encode($response));
}
?>
here method for upload:
private void uploadImage() {
StringRequest strReq = new StringRequest(Request.Method.POST, url_update_foto, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Response: " + response.toString());
try {
JSONObject jObj = new JSONObject(response);
success = jObj.getInt(TAG_SUCCESS);
// Cek error node pada json
if (success == 1) {
Log.d("Insert", jObj.toString());
Toast.makeText(UploadFoto.this, jObj.getString(TAG_MESSAGE), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(UploadFoto.this, jObj.getString(TAG_MESSAGE), Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Error: " + error.getMessage());
Toast.makeText(UploadFoto.this, error.getMessage(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters ke post url
Map<String, String> params = new HashMap<>();
//Converting Bitmap to String
String image = getStringImage(bitmap);
//Adding parameters
params.put("foto", image);
params.put("id_user", id);
return params;
}
};
AppController.getInstance().addToRequestQueue(strReq, tag_json_obj);
}
共 (0) 个答案