Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将图像从android上传到php服务器_Php_Android_Upload_Image - Fatal编程技术网

将图像从android上传到php服务器

将图像从android上传到php服务器,php,android,upload,image,Php,Android,Upload,Image,我正在尝试将一张照片从android设备上传到php网站。 为此,我使用了MultipartEntity编码 为此,我将作为外部jar文件添加到我的项目中 我想上传到php网站的是存储在SD卡上的图像。 为此,我在代码中执行以下操作: HttpPost httppost = new HttpPost("....the link to the webiste..."); MultipartEntity reqEntity = new MultipartEntity();

我正在尝试将一张照片从android设备上传到php网站。 为此,我使用了
MultipartEntity
编码

为此,我将
作为
外部jar文件添加到我的项目中

我想上传到php网站的是存储在
SD卡
上的
图像
。 为此,我在代码中执行以下操作:

HttpPost httppost = new HttpPost("....the link to the webiste...");

        MultipartEntity reqEntity = new MultipartEntity();
        StringBody sb=new StringBody("....");


        File file=new File("/sdcard/image.jpg");
        FileBody bin = new FileBody(file);
        reqEntity.addPart("android",bin);
        reqEntity.addPart("id", sb);

        httppost.setEntity(reqEntity);

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


       if (resEntity != null) {
            String page = EntityUtils.toString(resEntity);
            System.out.println("PAGE :" + page);
        }
但问题是,来自php服务器的响应总是一个断开的链接

下一步我想尝试的是使用

 MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
但不幸的是,我导入的
jar
没有用于
HttpMultipartMode.BROWSER\u COMPATIBLE
的类。因此,如果您能为我指出正确的方向,我将非常感激您还应该导入哪些内容才能工作……或者我应该如何将图像上载到服务器。 我必须说,服务器的构建目的是以这种方式上传照片:

method="post" enctype="multipart/form-data"
                      name="form" target="_self" id="form">
                    <input type="hidden" name="p" value="a" />
method=“post”enctype=“多部分/表单数据”
name=“form”target=“\u self”id=“form”>

谢谢

我建议不要使用
beta
库。你应该使用

你也需要

这些必须是您的导入:

      import org.apache.http.HttpResponse;
      import org.apache.http.client.ClientProtocolException;
      import org.apache.http.client.HttpClient;
      import org.apache.http.client.entity.UrlEncodedFormEntity;
      import org.apache.http.client.methods.HttpGet;
      import org.apache.http.client.methods.HttpPost;
      import org.apache.http.entity.mime.HttpMultipartMode;
      import org.apache.http.entity.mime.MultipartEntity;
      import org.apache.http.entity.mime.content.FileBody;
      import org.apache.http.entity.mime.content.StringBody;
      import org.apache.http.impl.client.DefaultHttpClient;
      import org.apache.http.message.BasicNameValuePair;

您可能正在寻找类似的内容:现在它告诉我:org.apache.james.mime4j.message.SingleBody类型无法解析。它是从此行的required.class文件中间接引用的:MultipartEntity reqEntity=new MultipartEntity();reqEntity.addPart(“安卓”,bin);请求实体添加部分(“id”,sb);我是一个重要的图书馆,我是一个独立的图书馆!也导入该类,然后导入org.apache.james.mime4j.message.SingleBody;在图书馆里,每个人都有自己的权利@乔治让我们