title: How to upload image from Android application to a webserver into a specific folder
body: <p>How to move an image from android to specified folder on a web server </p>
  
  <p>This is my android code</p>
  
  <pre><code>package com.example.bitmaptest;
  
  import java.io.ByteArrayOutputStream;
  import java.io.InputStream;
  import java.util.ArrayList;
  
  import org.apache.http.HttpEntity;
  import org.apache.http.HttpResponse;
  import org.apache.http.NameValuePair;
  import org.apache.http.client.HttpClient;
  import org.apache.http.client.entity.UrlEncodedFormEntity;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.impl.client.DefaultHttpClient;
  import org.apache.http.message.BasicNameValuePair;
  
  import android.app.Activity;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.os.Bundle;
  import android.util.Base64;
  import android.util.Log;
  
  public class Upload extends Activity {
  InputStream is;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      Bitmap bitmapOrg=BitmapFactory.decodeResource(getResources(),R.drawable.a1);
      ByteArrayOutputStream bao = new ByteArrayOutputStream();
      bitmapOrg.compress(Bitmap.CompressFormat.JPEG, 90, bao);
      byte[] ba = bao.toByteArray();
      String ba1 = Base64.encodeToString(ba, 0);
      ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
      nameValuePairs.add(new BasicNameValuePair("image", ba1));
  
      try {
  
          HttpClient httpclient = new DefaultHttpClient();
          HttpPost httppost = new HttpPost(
                  "http://0.0.0.7:80/android/base.php");
          httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
          HttpResponse response = httpclient.execute(httppost);
          HttpEntity entity = response.getEntity();
          is = entity.getContent();
      } catch (Exception e) {
          Log.e("log_tag", "Error in http connection " + e.toString());
      }
  
  }
  }
  </code></pre>
  
  <p>and this is my php script</p>
  
  <pre><code>$uploadedFile = $_FILES['image']['name'];
  
  $uploadedType = $_FILES['image']['type'];
  
  $temp = $_FILES['image']['tmp_name'];
  
  $error = $_FILES['image']['error'];
  
  if ($error &gt; 0) {
  die("File could not be uploaded. $error");
  }
  else {
      move_uploaded_file($temp, "images/".$uploadedFile);
      echo "Upload Complete. ".$uploadedType;
  }
  </code></pre>
  
  <p>When I send in android, httppost works, it shows in wireshark but the file is empty. There is no image.</p>