0

以下はruntime exeception、サーバーに画像をアップロードしようとしているときに取得したものです。 ここに画像の説明を入力

そして、ローカルサーバー(WAMP)を使用して画像をアップロードしようとしていますが、Androidコードは

Bitmap bitmap = BitmapFactory.decodeFile("/sdcard/Sunset.jpg");

     //   Bitmap bitmap = BitmapFactory.decodeResource(getResources(),R.drawable.background1); 
            ByteArrayOutputStream stream = new ByteArrayOutputStream();

            bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream); //compress to which format you want.

            byte [] byte_arr = stream.toByteArray();
            String image_str = Base64.encodeBytes(byte_arr);

            ArrayList<NameValuePair> nameValuePairs = new  ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("image",image_str));

            try{

                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost("http://192.168.1.49/android/upload_image.php");

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);

                String the_string_response = convertResponseToString(response);

                Toast.makeText(uploadimage.this, "Response  " + the_string_response, Toast.LENGTH_LONG).show();

            }catch(Exception e){
                  Toast.makeText(uploadimage.this, "ERROR " + e.getMessage(), Toast.LENGTH_LONG).show();

                  System.out.println("Error  http   connection"+e.toString());
            }

        }

        public String convertResponseToString(HttpResponse response) throws IllegalStateException, IOException{

             String res = "";
             StringBuffer buffer = new StringBuffer();

             inputStream = response.getEntity().getContent();
             int contentLength = (int) response.getEntity().getContentLength(); //getting content length…..

             Toast.makeText(uploadimage.this, "contentLength : " + contentLength, Toast.LENGTH_LONG).show();

             if (contentLength < 0){
             }
             else{
                    byte[] data = new byte[512];
                    int len = 0;

                    try
                    {
                        while (-1 != (len = inputStream.read(data)) )
                        {

                            buffer.append(new String(data, 0, len)); //converting to string and appending  to stringbuffer…..

                        }

                    }

                    catch (IOException e)
                    {
                        e.printStackTrace();
                    }

                    try
                    {
                        inputStream.close(); // closing the stream…..
                    }
                    catch (IOException e)
                    {
                        e.printStackTrace();
                    }   
                     res = buffer.toString();     // converting string buffer to string

                    Toast.makeText(uploadimage.this, "Result : " + res, Toast.LENGTH_LONG).show();

                    //System.out.println("Response => " +  EntityUtils.toString(response.getEntity()));

             }
  return res;

        }

}

これは、インターネットから取得した私のphpコードです。

<?php

    $base=$_REQUEST['image'];

     $binary=base64_decode($base);

    header('Content-Type: bitmap; charset=utf-8');

    $file = fopen('uploaded_image.jpg', 'wb');

    fwrite($file, $binary);

    fclose($file);

    echo 'Image upload complete!!, Please check your php file directory……';

?>

私の問題を解決するために、これで私を助けてくれる人はいますか。前もって感謝します

4

2 に答える 2

0

InetpubはSYSTEMユーザーによって作成されます。これは、管理者権限がない限り、そのサブディレクトリまたはそのサブディレクトリに変更を加えることは許可されていないことを意味します。inetpubフォルダーのアクセス許可を変更して、誰でもファイルを変更できるようにしてください。右クリック->プロパティ->...その後どうするか忘れてしまいました。(私は今Linuxにいます)。それでも問題が解決しない場合は、IISを管理者として実行していることを確認してください。

于 2011-10-19T05:02:45.223 に答える
0

c:\に追加のディレクトリを1つ作成してから、そのディレクトリに対して読み取り、書き込み、および実行のアクセス許可を与える必要があります。PHPコードに、保存場所の絶対パスを記述してください。

これで問題が解決する場合があります。

IISサーバーを管理者モードで実行することを忘れないでください。

于 2011-10-19T05:28:27.670 に答える