2013-01-22 2 views
0

이름과 이메일과 같은 일부 데이터가 포함 된 사진을 휴대 전화에서 업로드하고 싶습니다.추가 데이터가있는 사진을 PHP로 업로드

Android 기기에서 사진을 업로드하는 방법을 알고 휴대 전화와 서버간에 데이터를 보내는 방법을 알고 있지만 어떻게 동시에 할 수 있습니까?

별도로해야합니까? 귀하의 경우는 MultipartEntity 클래스를 사용해야에서

+0

당신이'MultipartEntity'를 시도? –

+0

여러 데이터 필드로 POST 보내기 – Leonidos

+0

게시물보기 http://stackoverflow.com/questions/14027882/try-to-upload-the-image-in-php-server-but-it-could-post-in-android/ 14028071 # 14028071. 이 대답을 줄 수 있습니다. –

답변

0

,

  MultipartEntity reqEntity = new MultipartEntity(); 
      reqEntity.addPart("name", new StringBody(name)); 
      reqEntity.addPart("email", new StringBody(email)); 

      if(imagePath.trim().length() != 0) { 
       reqEntity.addPart("profilePic", new FileBody(new File(imagePath))); 
      } 

      HttpClient hc = new DefaultHttpClient(); 
      HttpPost postMethod = new HttpPost(urlString); 
      HttpEntity resEntity; 
      HttpResponse response = null; 
      postMethod.setEntity(reqEntity); 
      response = hc.execute(postMethod); 
      resEntity = response.getEntity(); 
      response_str = EntityUtils.toString(resEntity);