单张图片无法在数据库中上传

时间:2017-05-02 05:01:15

标签: java android sql imageview

当我尝试上传图像并存储在数据库中时,它不存储数据或图像。

在我的应用程序中,我有一些EditText和6 ImageView。

当我插入所有六个图像然后它存储在数据库中但是当我上传一个或两个图像然后它不工作

这里是api

    <?php
            header('Content-Type: bitmap; charset=utf-8');
            $pannm = $_POST['abc'];
            $bpan = base64_decode($_POST['eabc']);
            if($pannm!='') {
            $filename1 = time().'_'.$pannm;
            $ppan = 'upload/';
            move_uploaded_file($_FILES['eabc']['tmp_name'], $ppan);
            $path1 = "upload/$filename1";
            $file1 = fopen('upload/'.$filename1, 'wb');
            fwrite($file1, $bpan);  
            fclose($file1);
            $response["success"] = 1;
            $response["message"] = "Successfully Added.";
            echo json_encode($response);
?>

这里的代码: -

main.java

    buy_image1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            edit.putInt("ImageID", 1);
            edit.commit();


        }
    });

public void selectImage()
{
    i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    startActivityForResult(i, RESULT_LOAD_IMAGE);
    i.putExtra("crop", "true");
    i.putExtra("outputX", 512);
    i.putExtra("outputY", 512);
    i.putExtra("aspectX", 1);
    i.putExtra("aspectY", 1);
    i.putExtra("scale", true);
}
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RESULT_LOAD_IMAGE && resultCode == getActivity().RESULT_OK && null != data)
    {
        final int IMAGE_MAX_SIZE = 1200000; // 1.2MP

        Uri selectedImage = data.getData();
        int imgid = 0;
        String[] filePathColumn = { MediaStore.MediaColumns.DATA };

        Cursor cursor = getActivity().getContentResolver().query(selectedImage, filePathColumn, null, null, null);
        cursor.moveToFirst();

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        picturePath = cursor.getString(columnIndex);
        cursor.close();
        Log.d("Value", picturePath);
        fileName = new File(picturePath).getName();
        // imgname.setText(fileName);

        String fileNameSegments[] = picturePath.split("/");
        fileName = fileNameSegments[fileNameSegments.length - 1];

        // MyParams.put("filename", fileName);
        Bitmap yourSelectedImage = BitmapFactory.decodeFile(picturePath);

        sp = getActivity().getSharedPreferences("Image ID", Context.MODE_PRIVATE);
        imgid = sp.getInt("ImageID", 0);
        Log.d("IMGID",Integer.toString(imgid));

        BitmapFactory.Options options = null;
        options = new BitmapFactory.Options();
        options.inSampleSize=5;
        bitmap = BitmapFactory.decodeFile(picturePath, options);
        ByteArrayOutputStream stream = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.JPEG, 60, stream);

        byte[] byte_arr = stream.toByteArray();
        // Encode Image to String
        encodedString = Base64.encodeToString(byte_arr, 0);
        //MyParams.put(I_IMA, encodedString);

        if(imgid == 1) {
            buy_image1.setImageBitmap(yourSelectedImage);
            img1 = fileName;
            encodedStringIMG1 = encodedString;
        }
        else if(imgid == 2) {
            buy_image2.setImageBitmap(yourSelectedImage);
            img2 = fileName;
            encodedStringIMG2 = encodedString;
        }
        if(imgid == 3) {
            buy_image3.setImageBitmap(yourSelectedImage);
            img3 = fileName;
            encodedStringIMG3 = encodedString;
        }
        else if(imgid == 4) {
            buy_image4.setImageBitmap(yourSelectedImage);
            img4 = fileName;
            encodedStringIMG4 = encodedString;
        }
        if(imgid == 5) {
            buy_image5.setImageBitmap(yourSelectedImage);
            img5 = fileName;
            encodedStringIMG5 = encodedString;
        }
        else if(imgid == 6) {
            buy_image6.setImageBitmap(yourSelectedImage);
            img6 = fileName;
            encodedStringIMG6 = encodedString;
        }
        else{
            Log.d("IMGID","IMAGE ID IS 0");
        }
}
private void service(
        String strwodname, String strfirm, String strowner,
        String strpartner1, String strpartner2, String strbranch,
        String strcontactperson, String strcontact,
        String strwhatsapp, String stremail, String strspinnercity,
        String straddress, String opendate1, String birthdate, String ani,
        String strpancard, String strtinnumber, String strbankname, String strbankholdername
        ,String strbankac,String strbankcity, String strifsccode,String strsecuritycheque,String strrefrence1,
        String strrefrence2,String strremarks,String i1,String encode1,String i2,String encode2,String i3,String encode3,String i4,
        String encode4,String i5,String encode5,String i6,String encode6
  ) {


      /*  */
        class AddVisitclass extends AsyncTask<String, Void, String> {
            ProgressDialog loading;
            RegisterUserClass ruc = new RegisterUserClass();

            @Override
            protected void onPreExecute() {
                super.onPreExecute();
            }
            @Override
            protected String doInBackground(String... params) {


                HashMap<String, String> param = new HashMap<String, String>();


                param.put("wname", params[0]);
                /*param.put("firm", params[1]);
                param.put("oname", params[2]);
                param.put("pname1", params[3]);
                param.put("pname2", params[4]);
                */param.put("branch", params[1]);
                param.put("cname", params[2]);
                param.put("contact", params[3]);
                param.put("whatsapp", params[4]);
                param.put("email", params[5]);
                param.put("city", params[6]);
                param.put("address", params[7]);
                param.put("bdate", params[8]);
                param.put("odate", params[9]);
                param.put("adate", params[10]);
                param.put("pancard", params[11]);
                param.put("tinno", params[12]);
                param.put("bnm", params[13]);
                param.put("bank_ac_holder", params[14]);
                param.put("bank_ac_no", params[15]);
                param.put("bcity", params[16]);
                param.put("ifsc_code", params[17]);
                param.put("cheque", params[18]);
                param.put("ref1", params[19]);
                param.put("ref2", params[20]);
                param.put("remarks", params[21]);

                param.put("pan", params[22]);
                param.put("epan", params[23]);
                param.put("aadhar", params[24]);
                param.put("eaadhar", params[25]);
                param.put("light", params[26]);
                param.put("elight", params[27]);
                param.put("vat", params[28]);
                param.put("evat", params[29]);
                param.put("vcard", params[30]);
                param.put("evcard", params[31]);
                param.put("shop", params[32]);
                param.put("eshop", params[33]);



                param.put("username",uid);
                String result = ruc.sendPostRequest(url_addwod, param);
//                Log.d("Result", result);
                Log.d("Data", param.toString());
                return result;
            }
            //@Override
            protected void onPostExecute(String result) {
                super.onPostExecute(result);
                //loading.dismiss();
                Toast.makeText(getActivity(), "W.O.D. added successfully...!!!", Toast.LENGTH_LONG).show();
               /* FragmentTransaction t = getActivity().getSupportFragmentManager().beginTransaction();
                TabFragment mFrag = new TabFragment();
                t.replace(com.Weal.sachin.omcom.R.id.framelayout, mFrag);
                t.commit();
*/
            }
        }
        AddVisitclass regi = new AddVisitclass();
        regi.execute(strwodname,strbranch,strcontactperson,strcontact,strwhatsapp,stremail,
                strspinnercity,straddress,opendate1,birthdate,ani,strpancard,strtinnumber,strbankname,strbankholdername,strbankac,
                strbankcity, strifsccode,strsecuritycheque,strrefrence1,strrefrence2,strremarks,i1,encode1,i2,encode2
                ,i3,encode3,i4,encode4,i5,encode5,i6,encode6);


    }

在添加按钮中,我调用addproperty()方法。

0 个答案:

没有答案