dongxi1965 2016-11-12 10:20
浏览 46

对于第二次更新照片不使用android studio和mysql进行更改

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);
}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端
    • ¥15 基于PLC的三轴机械手程序
    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作