试着上传PHP服务器的形象,但它可以发布。在机器人但它、试着、机器人、形象

2023-09-13 00:37:04 作者:11.我在原点

我试图通过与其他条目,如姓名出生日期身份证等画廊上传服务器的图像,所有的项目都在PHP服务器上载,除了形象,我没有下站的地方是我的错,请帮助。推荐任何其它code PLZ告诉我。 这里是我的code

 位图bitmapOrg = BitmapFactory.de codeFILE(imageselectedPath1);
     ByteArrayOutputStream宝=新ByteArrayOutputStream();

            //调整图像
            双幅= bitmapOrg.getWidth();
            双高= bitmapOrg.getHeight();
            双率= 400 /宽度;
            INT newheight =(int)的(比*高);
            的System.out.println(----宽度+宽);
            的System.out.println(----高度+高);
            Log.d(宽度,宽度+宽);
            Log.d(高度,高度+高);
            bitmapOrg = Bitmap.createScaledBitmap(bitmapOrg,400,
                    newheight,真正的);
            //这里你可以定义。PNG以及
            bitmapOrg.com preSS(Bitmap.Com pressFormat.JPEG,99,宝);
            byte []的BA = bao.toByteArray();
            字符串BA1 = Base64.en codeBytes(BA);
            Log.d(上传,上传+ BA 1);

            ArrayList的<的NameValuePair> namevaluepairs中=新的ArrayList<的NameValuePair>();

            nameValuePairs.add(新BasicNameValuePair(USER_ID,mSignMessg));
            nameValuePairs.add(新BasicNameValuePair(姓名,mname.getText()的toString())。);
            nameValuePairs.add(新BasicNameValuePair(DOB,mbirthday.getText()的toString())。);
            nameValuePairs.add(新BasicNameValuePair(生物,mbio.getText()的toString())。);
            nameValuePairs.add(新BasicNameValuePair(性,mSexValue));
            nameValuePairs.add(新BasicNameValuePair(profile_status,0));
            nameValuePairs.add(新BasicNameValuePair(位置,mlocation.getText()的toString()));

            nameValuePairs.add(新BasicNameValuePair(形象,BA1));
            Log.d(userfile的,userfile的+ BA1);

            // nameValuePairs.add(新BasicNameValuePair(形象,BA1));

            尝试 {
                HttpClient的HttpClient的=新DefaultHttpClient();
                HttpPost httppost =新HttpPost(
                        http://iapptechnologies.com/snapic/profileXml.php);
                httppost.setEntity(新UrlEn codedFormEntity(namevaluepairs中));

                Log.d(namevaluepairs中,namevaluepairs中+ namevaluepairs中);

                HTT presponse响应= httpclient.execute(httppost);
                HttpEntity实体= response.getEntity();

                //打印的反响
                输出= EntityUtils.toString(实体);
                Log.i(GET RESPONSE--,输出);
                Log.d(GET RESPONSE--,输出);

                //是= entity.getContent();
                Log.e(log_tag ******,良好的连接);
                的System.out.println(gudconection);
                Log.d(上帝连接,GUD连接);

                bitmapOrg.recycle();

            }赶上(例外五){

                Log.e(logCatch块***,
                        在HTTP连接错误+ e.toString());
                Log.d(log_catch块******,错误的HTTP连接
                        + e.toString());
            }

              Log.d(IMAGE_NAME,IMAGE_NAME+ IMAGE_NAME);
 

解决方案

如果ULR喜欢这个 http://iapaaaa.com/snapic/profileXml.php?user_id=2&name=joe&dob=2000-01-10&bio=bla BLA BLA和放大器;性别= 1&安培; profile_status = 0&放大器;位置=英格兰和放大器;的用户文件= user_photo.png

使用code      BitmapFactory.Options选项=新BitmapFactory.Options();

  //与inSampleSize集德code位图
            options.inJustDe codeBounds = TRUE;
            //图像路径`String`,你的形象所在
            BitmapFactory.de codeFILE(selectedPath1,期权);

            INT bitmapWidth = 400;
            INT bitmapHeight = 250;
            最终诠释身高= options.outHeight;
            最终诠释宽度= options.outWidth;
            INT inSampleSize = 1;
            如果(高度> bitmapHeight ||宽度GT; bitmapWidth){
                如果(宽>高度){
                    inSampleSize = Math.round((浮点)高度
                            /(浮点)bitmapHeight);
                } 其他 {
                    inSampleSize = Math.round((浮点)宽
                            /(浮点)bitmapWidth);
                }
            }

            options.inJustDe codeBounds = FALSE;
            options.inSampleSize = inSampleSize;

            位图bmpScale = BitmapFactory.de codeFILE(selectedPath1,
                    选项​​);

            ByteArrayOutputStream BOS =新ByteArrayOutputStream();

            //的COM pressFormat设置为JPG格式,您可以更改为PNG或
            //不管你
            // 想;

            bmpScale.com preSS(比较pressFormat.JPEG,100,BOS);
            bmpScale.com preSS(比较pressFormat.JPEG,100,BOS);

            byte []的数据= bos.toByteArray();
            MultipartEntity实体=新MultipartEntity(
                    HttpMultipartMode.BROWSER_COMPATIBLE);
            // entity.addPart(阿凡达,新ByteArrayBody(数据,mSignMessg +
            // - +新的随机()nextInt(1000)+.JPG))。

            entity.addPart(userfile的新ByteArrayBody(数据,pic.jpg));
            //在实体添加其他名称值对。
            ArrayList的<的NameValuePair> namevaluepairs中=新的ArrayList<的NameValuePair>();

            namevaluepairs中
                    。新增(新BasicNameValuePair(user_ID的,mSignMessg));
            nameValuePairs.add(新BasicNameValuePair(名,MNAME
                    。.getText()的toString()));
            nameValuePairs.add(新BasicNameValuePair(DOB,mbirthday
                    。.getText()的toString()));
            nameValuePairs.add(新BasicNameValuePair(生物,mbio.getText()
                    的ToString()));
            nameValuePairs.add(新BasicNameValuePair(性,mSexValue));
            namevaluepairs中
                    。新增(新BasicNameValuePair(profile_status,0));
            nameValuePairs.add(新BasicNameValuePair(位置,mlocation
                    。.getText()的toString()));

            // nameValuePairs.add(新BasicNameValuePair(形象,BA1));
            Log.d(userfile的,userfile的+ BA1);

            // nameValuePairs.add(新BasicNameValuePair(形象,BA1));

            的for(int i = 0; I< nameValuePairs.size();我++){

                尝试 {
                    entity.addPart(
                            nameValuePairs.get(ⅰ).getName(),
                            新StringBody(nameValuePairs.get(ⅰ).getValue()));
                }赶上(UnsupportedEncodingException E){
                    // TODO自动生成的catch块
                    Log.d(respons,形象respons+ E);
                    e.printStackTrace();
                }

            }

            // httppost.setEntity(实体);
            //
            // Htt的presponse响应= httpClient.execute(httppost);

            尝试 {
                HttpClient的HttpClient的=新DefaultHttpClient();
                HttpPost httppost =新HttpPost(http://technologies.com/snapic/profileXml.php);

                httppost.setEntity(实体);

                Log.d(namevaluepairs中,namevaluepairs中+ namevaluepairs中);

                HTT presponse响应= httpclient.execute(httppost);
                HttpEntity使用实体= response.getEntity();

                //打印的反响
                输出= EntityUtils.toString(response.getEntity());
                Log.i(GET RESPONSE--,输出);
                Log.d(GET RESPONSE--,输出);

                //是= entity.getContent();
                Log.e(log_tag ******,良好的连接);
                的System.out.println(gudconection);
                Log.d(上帝连接,GUD连接);

                bitmapOrg.recycle();

            }赶上(例外五){

                Log.e(logCatch块***,
                        在HTTP连接错误+ e.toString());
                Log.d(log_catch块******,错误的HTTP连接
                        + e.toString());
            }
 
索尼将推两款新移动应用, 即拍即传 是其最大亮点

I try to upload the image in server through the gallery with other entries like name DOB id etc , all the entries are uploaded except image in php server , I did not under stand where is my mistake please help . Suggest any another code plz tell me. here is my code

          Bitmap bitmapOrg = BitmapFactory.decodeFile(imageselectedPath1);
     ByteArrayOutputStream bao = new ByteArrayOutputStream();

            // Resize the image
            double width = bitmapOrg.getWidth();
            double height = bitmapOrg.getHeight();
            double ratio = 400 / width;
            int newheight = (int) (ratio * height);
            System.out.println("———-width" + width);
            System.out.println("———-height" + height);
            Log.d("width ", "width  " + width);
            Log.d("height ", "height " + height);
            bitmapOrg = Bitmap.createScaledBitmap(bitmapOrg, 400,
                    newheight, true);
            // Here you can define .PNG as well
            bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 99, bao);
            byte[] ba = bao.toByteArray();
            String ba1 = Base64.encodeBytes(ba);
            Log.d("uploading  ", "uploading   " + ba1);

            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

            nameValuePairs.add(new BasicNameValuePair("user_id", mSignMessg));
            nameValuePairs.add(new BasicNameValuePair("name", mname.getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("dob", mbirthday.getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("bio", mbio.getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("sex", mSexValue));
            nameValuePairs.add(new BasicNameValuePair("profile_status", "0"));
            nameValuePairs.add(new BasicNameValuePair("location", mlocation.getText().toString()));

            nameValuePairs.add(new BasicNameValuePair("image", ba1));
            Log.d("userfile", "userfile " + ba1);

            // nameValuePairs.add(new BasicNameValuePair("image", ba1));

            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(
                        "http://iapptechnologies.com/snapic/profileXml.php");
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                Log.d("nameValuePairs", "nameValuePairs " + nameValuePairs);

                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();

                // print responce
                outPut = EntityUtils.toString(entity);
                Log.i("GET RESPONSE—-", outPut);
                Log.d("GET RESPONSE—-", outPut);

                // is = entity.getContent();
                Log.e("log_tag ******", "good connection");
                System.out.println("gudconection");
                Log.d("god connection ", "gud connection ");

                bitmapOrg.recycle();

            } catch (Exception e) {

                Log.e("logCatch block***",
                        "Error in http connection " + e.toString());
                Log.d("log_catch block ******", "Error in http connection "
                        + e.toString());
            }

              Log.d("image_name","image_name "+image_name); 

解决方案

if ulr like this http://iapaaaa.com/snapic/profileXml.php?user_id=2&name=joe&dob=2000-01-10&bio=bla bla bla&sex=1&profile_status=0&location=England&userfile=user_photo.png

use this code BitmapFactory.Options options = new BitmapFactory.Options();

            // Decode bitmap with inSampleSize set
            options.inJustDecodeBounds = true;
            // image path `String` where your image is located
            BitmapFactory.decodeFile(selectedPath1, options);

            int bitmapWidth = 400;
            int bitmapHeight = 250;
            final int height = options.outHeight;
            final int width = options.outWidth;
            int inSampleSize = 1;
            if (height > bitmapHeight || width > bitmapWidth) {
                if (width > height) {
                    inSampleSize = Math.round((float) height
                            / (float) bitmapHeight);
                } else {
                    inSampleSize = Math.round((float) width
                            / (float) bitmapWidth);
                }
            }

            options.inJustDecodeBounds = false;
            options.inSampleSize = inSampleSize;

            Bitmap bmpScale = BitmapFactory.decodeFile(selectedPath1,
                    options);

            ByteArrayOutputStream bos = new ByteArrayOutputStream();

            // CompressFormat set up to JPG, you can change to PNG or
            // whatever you
            // want;

            bmpScale.compress(CompressFormat.JPEG, 100, bos);
            bmpScale.compress(CompressFormat.JPEG, 100, bos);

            byte[] data = bos.toByteArray();
            MultipartEntity entity = new MultipartEntity(
                    HttpMultipartMode.BROWSER_COMPATIBLE);
            // entity.addPart("avatar", new ByteArrayBody(data,mSignMessg +
            // "-" + new Random().nextInt(1000) + ".jpg"));

            entity.addPart("userfile", new ByteArrayBody(data, "pic.jpg"));
            // add your other name value pairs in entity.
            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

            nameValuePairs
                    .add(new BasicNameValuePair("user_id", mSignMessg));
            nameValuePairs.add(new BasicNameValuePair("name", mname
                    .getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("dob", mbirthday
                    .getText().toString()));
            nameValuePairs.add(new BasicNameValuePair("bio", mbio.getText()
                    .toString()));
            nameValuePairs.add(new BasicNameValuePair("sex", mSexValue));
            nameValuePairs
                    .add(new BasicNameValuePair("profile_status", "0"));
            nameValuePairs.add(new BasicNameValuePair("location", mlocation
                    .getText().toString()));

            // nameValuePairs.add(new BasicNameValuePair("image", ba1));
            Log.d("userfile", "userfile " + ba1);

            // nameValuePairs.add(new BasicNameValuePair("image", ba1));

            for (int i = 0; i < nameValuePairs.size(); i++) {

                try {
                    entity.addPart(
                            nameValuePairs.get(i).getName(),
                            new StringBody(nameValuePairs.get(i).getValue()));
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    Log.d("respons", "image respons " + e);
                    e.printStackTrace();
                }

            }

            // httppost.setEntity(entity);
            //
            // HttpResponse response = httpClient.execute(httppost);

            try {
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://technologies.com/snapic/profileXml.php");

                httppost.setEntity(entity);

                Log.d("nameValuePairs", "nameValuePairs " + nameValuePairs);

                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity1 = response.getEntity();

                // print responce
                outPut = EntityUtils.toString(response.getEntity());
                Log.i("GET RESPONSE—-", outPut);
                Log.d("GET RESPONSE—-", outPut);

                // is = entity.getContent();
                Log.e("log_tag ******", "good connection");
                System.out.println("gudconection");
                Log.d("god connection ", "gud connection ");

                bitmapOrg.recycle();

            } catch (Exception e) {

                Log.e("logCatch block***",
                        "Error in http connection " + e.toString());
                Log.d("log_catch block ******", "Error in http connection "
                        + e.toString());
            }