i had some problems when updating photo profile in android studio and mysql. but for the process update to database there is no problem and photo updating success. for the first time update photo profile success changed in imageview and photo was upload to folder "upload" inside xampp, for the second update it won't changed instead in imageview it using previous update. but in folder "upload" inside xampp the previous photo is changed with the new photo i was uploaded before. i try to refresh activity with onRestart() it failed, i hope you understand for my question. please help me.
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);
}